2011-08-22 40 views
3

我没有得到任何错误,但我没有收到文件复制或者:PHP复制或移动上传的文件 - 什么也没有发生,但没有错误

$upload_folder = "uploads/"; 

$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); 

$prefix = date("YmdHis"); 
$path_of_uploaded_file = "$upload_folder$prefix-$name_of_uploaded_file"; 
$tmp_path = $_FILES["uploaded_file"]["tmp_name"]; 

if(is_uploaded_file($tmp_path)) 
{ 
    if(!copy($tmp_path,$path_of_uploaded_file)) 
    { 
    $errors .= '\n error while copying the uploaded file'; 
    } 
} 

echo $path_of_uploaded_file; 
echo $name_of_uploaded_file; 
echo $errors; 

这工作正常在Windows开发环境,但是部署到Linux Web服务器就是这样做的。我们最初得到一个复制错误,然后我们添加了上传目录的权限。现在我们什么都没有。

我也试过这与move_uploaded_file,没有错误,但在上传目录中没有结果文件。

+0

您完全确定该文件的路径是正确的? –

+0

@Evan Mulawski我们对它进行了回应(它在Windows上工作) - 它显示完整路径和基本名称都很好。我们也回应了$ tmp_path,这看起来很好(但我们似乎没有足够快的速度看到文件出现 - 我认为它的寿命很短)。如果该文件不在tmp中,我们应该会看到一个复制错误,我想呢? –

+0

你的窗体中是否有'MAX_FILE_SIZE'输入?你可能会这样做,所以尝试将值设置为'0'(零)。 –

回答

6

也许你可以添加一个检查,如果is_uploaded_file返回true。

if(is_uploaded_file($tmp_path)) 
{ 
    if(!copy($tmp_path,$path_of_uploaded_file)) 
    { 
    $errors .= '\n error while copying the uploaded file'; 
    } 
} else { 
    $errors .= '\n error while uploading file'; // maybe upload_max_filesize exceeded 
// try to get the specific error 

switch($_FILES['uploaded_file']['error']){ 
    case 0: //no error; possible file attack! 
     echo "There was a problem with your upload."; 
     break; 
    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini 
     echo "The file you are trying to upload is too big."; 
     break; 
    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form 
     echo "The file you are trying to upload is too big."; 
     break; 
    case 3: //uploaded file was only partially uploaded 
     echo "The file you are trying upload was only partially uploaded."; 
     break; 
    case 4: //no file was uploaded 
     echo "You must select an image for upload."; 
     break; 
    default: //a default error, just in case! :) 
     echo "There was a problem with your upload."; 
     break; 

} 

也许你的upload_max_filesize超标,或者有其他的服务器设置,不允许上传。

查看php dokumentation了解更多关于可能的问题的信息。

+0

'$ _FILES ['uploaded_file'] ['error']'为0,'is_uploaded_file($ tmp_path)'为真 –

+0

好的,但现在我们知道了至少可以确定上传本身工作。我想你已经试图转储$ _FILES变量,$ tmp_path变量和$ path_of_uploaded_file变量,并检查文件系统中是否有文件?我猜想上传的文件的位置可能存在问题,例如,你是否尝试在场名上调用realpath函数并检查它们是否正确? –

+0

转储的名称,类型,tmp_name,错误,大小 - 一切看起来不错。让我们看看实际路径给出了什么。 (不用说,PHP对我而言是新事物)。 –

1
$upload_folder = "uploads/"; 
$path_of_uploaded_file = "$upload_folder$prefix-$name_of_uploaded_file"; 

让你$path_of_uploaded_file

$path_of_uploaded_file = "$upload_folder/$prefix-$name_of_uploaded_file"; 
相关问题