2011-11-05 116 views
0

我正在使用uploadify,我的問題是這些文件沒有上傳。Uploadify腳本沒有錯誤,但沒有上傳

這是我的代碼:

在uploadify.php我給自己定了根路徑:/

像這樣:

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

那麼剩下的腳本:

<script type="text/javascript"> 
jQuery(document).ready(function() { 


    $('#file_upload').uploadify({ 
     'uploader' : '/myIncludes/UploadiftyFolder/uploadify.php', 
     'swf' : '/myIncludes/UploadiftyFolder/uploadify.swf', 
     'cancelImg' : '/myIncludes/UploadiftyFolder/cancel.png', 
     'folder' : '/myUploads/UploadsDirectory/images/', 
     'auto'  : true, 
     'multi'   : false, 
     'checkExisting' : false 
     }); 
}); 
</script> 

//Finally 

<input id="file_upload" type="file" name="Filedata" /> 
<a href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a> 

當我嘗試上傳圖片時,它一切正常(看起來太),它說 - 完成...

但是沒有任何內容正在上傳。

任何想法?

UPDATE:

這裏是我的服務器結構的路徑:

我的路徑:

root/myIncludes/UploadiftyFolder/ <--Here are all the uploadify files 

root/myUploads/UploadsDirectory/images/ <--Here is where I need to upload 

這裏是uploadify我的當前設置:

folder --> '/myUploads/UploadsDirectory/images/', 

and in uploadify.php --> $targetFolder = '/'; // Relative to the root 

這裏是休息uploadify.php文件的文件...我沒有改變任何東西:

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

先給 「〜/」 文件夾上傳

(OR)之前這裏是整個腳本:

<script type="text/javascript"> 
    $(window).load(
function() { 
    $("#fileInput1").uploadify({ 
     'uploader': 'scripts/uploadify.swf', 
     'cancelImg': 'images/cancel.png', 
     'buttonText': 'Browse Files', 
     'script': 'UploadVB.ashx', 
     'folder': 'uploads', 
     'fileDesc': 'Image Files', 
     'fileExt': '*.jpg;*.jpeg;*.gif;*.png', 
     'queueSizeLimit': 9999, 
     'simUploadLimit': 2, 
     'sizeLimit': 4000000, 
     'multi': true, 
     'auto': true, 
     'onComplete': function (event, queueID, fileObj, response, data) { 
         $("#thumbnail").append(response) 

     }, 

     'onError': function (event, ID, fileObj, errorObj) { 
      alert(errorObj.type + ' Error: ' + errorObj.info); 
     } 


    }); 
} 
); 
</script> 
+0

我正在使用php上傳器而不是..'uploader':'/files/uploadify.php'...但是我添加了oncomplete和onerror,但沒有得到任何回報。 – Satch3000

+0

這只是問題與所需的上傳文件夾確保參考路徑是正確的上傳文件夾在您的uploadify.php – coder

4

對我來說,問題是在uploadify.php文件。他們正在使用:

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

$targetFolder由您在頂部定義。

再後來:

move_uploaded_file($tempFile,$targetFile); 

默認例子追加的目標文件夾到的$_SERVER['DOCUMENT_ROOT']結束。我的$_SERVER['DOCUMENT_ROOT']實際上是C:\xampp\htdocs。因此,爲了使你的工作目標文件夾必須是:

$targetFolder = "/yourSiteFolder/wherever/your/upload/folder/is";

我做了什麼:

擺脫$_SERVER['DOCUMENT_ROOT']乾脆。這裏是我的uploadify.php文件:

<?php 
/* 
Uploadify v3.1.0 
Copyright (c) 2012 Reactive Apps, Ronnie Garcia 
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/ 

// Define a destination 
//$targetFolder = '/sandbox/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($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]); 
     echo '1'; 
    } else { 
     echo 'Invalid file type.'; 
    } 
} 
?> 

主要的變化是,我已經更換了這一點:

move_uploaded_file($tempFile,$targetFile); 

與此:

move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]); 

然後註釋掉幾行文字間沒有」不再需要了。

這是我check-exists.php文件:

<?php 
/* 
Uploadify v3.1.0 
Copyright (c) 2012 Reactive Apps, Ronnie Garcia 
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/ 

// Define a destination 
//$targetFolder = 'uploads'; // Relative to the root and should match the upload folder  in the uploader script 

if (file_exists("uploads/" . $_POST['filename'])) { 
    echo 1; 
} else { 
    echo 0; 
} 
?> 

這是我的jQuery代碼:

$(function() { 
    $("#uploadify").uploadify({ 
     height  : 30, 
     swf   : 'uploadify/uploadify.swf', 
     uploader  : 'uploadify/uploadify.php', 
     width   : 120 
    }); 
}); 

有關我的網站的文件結構的說明:

所有uploadify文件在我的網站的根目錄中名爲uploadify的文件夾中。在uploadify之內有一個名爲uploads的文件夾,這是上傳文件的位置。

希望有所幫助。

+0

嘿,這對我很有用。 –

1

對我來說,我所要做的就是擺脫$ targetPath定義中的$ _SERVER ['DOCUMENT_ROOT']。然後我還使用「上傳」而不是「/ uploads」作爲我的$ targetFolder。

2

我在這裏嘗試了所有其他的建議,但沒有一個爲我工作。然後我意識到Uploadify的3.2版(以及以前的版本)需要時間戳和哈希標記才能完成上傳。

首先,我必須將腳本從外部JS文件移動到我的PHP文件,以便我可以從PHP獲取時間戳。 (你也可以通過隱藏的輸入值或其他方法來做到這一點,但這是最簡單的方法。)然後,我必須將'formData' option添加到我的Uploadify調用中,以及一些獲取時間戳的PHP代碼,並使用獨特的鹽(你應該更改爲隨機字符串):

<?php $timestamp = time();?> 
<script> 
$('#file_upload').uploadify({ 
    'swf'  : '/uploadify/uploadify.swf', 
    'uploader' : '/uploadify/uploadify.php', 
    'formData' : { 
     'timestamp' : '<?php echo $timestamp;?>', 
     'token'  : '<?php echo md5("unique_salt" . $timestamp);?>' 
    } 
}); 
</script> 

儘管此代碼似乎在3.2版本是必需的,它不是在implementation documentation提及。我必須查看下載包中的index.php文件才能找到它。

相關問題