Move_uploaded_file不起作用。我已经尝试了一切,但似乎没有任何工作。
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
error_reporting( E_ALL ^ E_DEPRECATED );
mysql_connect("127.0.0.1","root","");
mysql_select_db("v-u-a-p");
if(isset($_POST['submit']))
{
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
if (move_uploaded_file($temp, "/files/".$name)) {
print "Received {$_FILES['file']['name']} - its size is {$_FILES['userfile']['size']}";
} else {
print "Upload failed!";
}
$url="http://127.0.0.1/Number1Edward/files/$name";
mysql_query("INSERT INTO `videos` VALUE ('','$name','$url')");
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Number_1_Edward</title>
<link rel="stylesheet" href="style.css?version=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#sidebar-btn').click(function(){
$('#sidebar').toggleClass('visable');
});
});
</script>
</head>
<body>
<div id="box">
<center><h9 id="Logo">Number_1_Edward</h9></center>
</div>
<div id="sidebar">
<ul>
<li><a href="view.php">Home</a></li>
<li><a href="upload.php">Upload</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="#">About</a></li>
</ul>
<div id="sidebar-btn">
<span></span>
<span></span>
<span></span>
</div>
</div>
<div id='box'>
<h1>Videos and Photos:</h1><p>Upload your videos and photos</p>
<form action="view.php" method='POST' enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" name="submit" value="Upload!"/><br/>
<textarea name="text" cols="40" rows="4" placeholder="Write a discription!(You must right a discription or it wont upload)" type="text"></textarea>
</form>
<?php
if(isset($_POST['submit']))
{
echo"<br/>".$name." has been uploaded";
}
?>
</div>
</body>
</html>
答案 0 :(得分:1)
很高兴使用__DIR__
确保/files/
符合您的想法。如下。
最可能的答案是,您尝试写入的目录上存在权限问题,因此您可能希望获得对目录的引用,然后检查is_writable()
。
$name = __DIR__.'/files/' . $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
if (move_uploaded_file($temp, $name)) {
print "Received {$_FILES['file']['name']} - its size is {$_FILES['userfile']['size']}";
} else {
print "Upload failed!";
}