PHP上传文件失败
问题描述:
我正在尝试将文件上传到本地服务器,但始终失败.
I'm trying to upload a file to my local server, but it keeps being unsuccessful.
我所有的文件都在/var/www/html/ 但是我在html文件夹中创建了一个名为uploads的文件夹,并将其权限更改为777(从搜索中获取的平均费用最适合我的需求)
All my files are inside /var/www/html/ However I made a folder called uploads in the html folder, and I changed its permissions to 777 (what I took on average from searching was the best for my needs)
这是我的代码: index.html
<!DOCTYPE html>
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
upload.php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES['fileToUpload']['name']);
echo "Target File: " . $target_file . "<br />";
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
答
您的输入文件为
<input name="uploadedfile" type="file" />
因此将$_FILES['fileToUpload']['name']
更改为$_FILES['uploadedfile']['name']
$_FILES['uploadedfile']['name']
必须具有文件字段的Name
属性值
$_FILES['uploadedfile']['name']
Must have the value of Name
attribute of your file field