PHP 上传脚本无法正常运行且 Apache 日志中没有错误

PHP upload script not functioning and no error on apache logs

我使用来自 tizag 的资源创建了一个上传脚本,该脚本返回了一个屏幕错误,但在 apache 日志中没有错误。

HTML表格

 <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 知识有限,请记住这一点。

亲切的问候,

马克·库托

首先确保php配置为允许文件上传。 在你的 "php.ini" 文件中搜索指令,并将其设置为 ON,

file_uploads= ON

来源 : http://www.w3schools.com/php/php_file_upload.asp

这一行:

$target = $target_path . basename($_FILES['uploadedfile']['name'][0] );

就目前而言,$target 只是一个杂散变量,未在其他任何地方使用。

应该读作:

$target_path = $target_path . basename($_FILES['uploadedfile']['name'][0] );

"I created an upload script using the resources from 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!";
}

此外,您在 ['uploadefile'] 中有错字,应该读作 ['uploadedfile']