我确保/ tmp文件夹是可写的,并且在php.ini
中upload_max_filesize = 5M
post_max_size = 8M
和我的upload.html
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
和我的upload_file.php
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
move_uploaded_file ($_FILES["file"]["tmp_name"] , '/var/www/html/web' );
}
?>
这是输出
Upload: screenshot 2013-12-30 15:00:54.png
Type: image/png
Size: 201.8154296875 kB
Stored in: /tmp/phpEdIgXr
但/ tmp / phpEdIgXr不存在!
答案 0 :(得分:2)
只需输入以下代码即可试用。它可能对你有帮助。
if ($_FILES["file"]["error"] > 0)
{
echo "Apologies, an error has occurred.";
echo "Error Code: " . $_FILES["file"]["error"];
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"[YOUR FOLDER PATH]".$_FILES["file"]["name"]);
}
答案 1 :(得分:0)
对于要在目录中显示的任何上传文件,您需要chmod 777
该文件夹。