2011-11-06 109 views
0

我試圖讓uploadify上傳,但它返回了幾個錯誤:Uploadify錯誤。沒有上傳圖片。

下面是錯誤:

<b>Warning</b>: move_uploaded_file(/home/mydomain/public_html/uploadslogo.png) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: Permission denied in <b>/home/mydomain/public_html/uploadify/uploadify.php</b> on line <b>37</b><br /> 
<br /> 


<b>Warning</b>: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpvoUwxK' to '/home/mydomain/public_html/uploadslogo.png' in <b>/home/domain/public_html/uploadify/uploadify.php</b> on line <b>37</b><br /> 
1true 

這裏是uploadify.php代碼:

<?php 

$targetFolder = '/uploads'; // Relative to the root 

if (!empty($_FILES)) { 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
    $targetFile = rtrim($targetPath,'/') . $_FILES['Filedata']['name']; 

    // Validate the file type 
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions 
    $fileParts = pathinfo($_FILES['Filedata']['name']); 

    if (in_array($fileParts['extension'],$fileTypes)) { 
     move_uploaded_file($tempFile,$targetFile); 
     echo '1'; 
    } else { 
     echo 'Invalid file type.'; 
    } 
} 
?> 

回答

1

你錯過uploads目錄後的尾部斜線。嘗試:

$targetFolder = '/uploads/'; // Relative to the root 

你也想改變:

$targetFile = rtrim($targetPath,'/') . $_FILES['Filedata']['name']; 

要:

$targetFile = $targetPath . $_FILES['Filedata']['name']; 
+0

改變了它,但仍得到相同的錯誤:警告:move_uploaded_file(/家/ mydomain/public_html/uploadslogo.png)[function.move-uploaded-file]:無法打開流:在/home/mydomain/public_html/uploadify/uploadify.php中拒絕了權限 on line
Satch3000

+0

尾部的斜線正在被以下行刪除: $ targetFile = rtrim($ targetPath,'/')。 $ _FILES [ 'Filedata上'] [ '名']; 將其更改爲: $ targetFile = $ targetPath。 $ _FILES [ 'Filedata上'] [ '名']; – BenM