我使用 tizag 的资源创建了一个上传脚本,该脚本返回屏幕上的错误,但 apache 日志中没有错误。
网页表单
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="90000000" />
Select video to upload:
Please choose a file: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
PHP代码
<?php
$target_path = "/var/www/html/upload/";
$target = $target_path . basename($_FILES['uploadedfile']['name'][0] );
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'] [0], $target_path))
{
echo "The file ". basename( $_FILES['uploadefile']['name'] [0]). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
这应该不难实现,但是由于 apache 上没有错误,我很难进行故障排除。我的php知识是有限的,所以请记住这一点。
亲切问候
马克·科托
这一行:
$target = $target_path . basename($_FILES['uploadedfile']['name'][0] );
就目前而言,$target
只是一个杂散变量,没有在其他任何地方使用。
其内容应为:
$target_path = $target_path . basename($_FILES['uploadedfile']['name'][0] );
"我使用 tizag 的资源创建了一个上传脚本"
您遵循的 Tizag 教程不会更改其变量。
他们的例子:
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
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!";
}
- 来源: http://www.tizag.com/phpT/fileupload.php
另外,您在['uploadefile']
中有一个错别字,应显示为['uploadedfile']
首先确保 php 配置为允许文件上传。在您的"php.ini"文件中搜索该指令,并将其设置为 ON,
file_uploads= ON
来源 : http://www.w3schools.com/php/php_file_upload.asp