PHP上传文件失败 [英] PHP Uploading file unsuccessful

查看:96
本文介绍了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

这篇关于PHP上传文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆