2012-02-20 73 views
0

我使用的PHP在此基礎上現場閃光燈/ AJAX文件上傳 - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/問題與阿賈克斯上傳

有一個在我收到的行爲有點不一致。

其中一個結果是將進程掛起,看起來像100%。 (我可以取消並在頁面上做其他事情,但我只是沒有更進一步。)

另一個是我點擊upload_success_handler但文件仍然沒有上傳到服務器。我甚至暫時將我的權限更改爲777,以排除所有問題,但仍無法上傳。

如果任何人有任何這種類型的事情的經驗,我想問什麼發送到ajax調用文件,它是如何發送(get/post)。另外,我需要在由ajax調用的文件上做什麼,以及我必須返回什麼?我是否只是通過回顯文件名來「返回」文件名,或者我是否真的使用了「返回」命令,就像它是一個函數一樣。所有它在博客上說的是

處理程序應該將上傳的文件保存到磁盤,然後返回一個唯一的標記,例如GUID或文件名,以標識剛上傳的文件。

目前我有我在該文件中的代碼爲的就是讓

<?php 
ini_set('post_max_size', 510000000); 
ini_set('upload_max_filesize', 500000000); 
ini_set('max_input_time', 20); 
ini_set('memory_limit', 520000000); 

if (!empty($_FILES['file']['name'])) //checking if file upload box contains a value 
{ 

    $saveDirectory = 'videos/';   //name of folder to upload to 
    $tempName = $_FILES['file']['tmp_name']; //getting the temp name on server 
    $fileName1 = $_FILES['file']['name'];  //getting file name on users computer 

    $test = array(); 
    $test = explode(".", $fileName1); 
    if((count($test) > 2) || ($test[1] != "avi" && $test[1] != "AVI" && $test[1] != "flv" && $test[1] != "FLV" && $test[1] != "mov" && $test[1] != "MOV" && $test[1] != "mpeg" && $test[1] != "MPEG" && $test[1] != "mp4" && $test[1] != "MP4" && $test[1] != "wmv" && $test[1] != "WMV")){ 
     $err .= "Invalid file type. Files must have only one period \".\" and be of type .avi .flv .mov .mpeg .mp4 or .wmv"; 
     echo $err; 

    }else{ 

     $count = 1; 
     do{ 
     $link = $saveDirectory . $count . $fileName1; 
     $count++; 
     }while(is_file($link)); 
     if (move_uploaded_file($tempName, $link)) //Moves the temp file on server 
     {           //to directory with real name 


      echo $link; 

     } 
     else 
     { 
      $err .= "There was an error while uploading the file."; 

      echo $err; 
     } 
    } 
} 
?> 
+0

任何人有任何見解?先進的謝謝你。 – 2012-02-20 20:30:22

+0

我現在每次都得到相同的行爲。它似乎可以成功上傳頁面,甚至在上傳完成後,當我在螢火蟲中查看頁面時,它甚至會將文件的名稱插入到隱藏的輸入中。我甚至可以提交併將所有正確的數據插入到數據庫中。但是,該文件不會移動到服務器。我打開了錯誤報告,並且權限已經打開。 – 2012-02-20 22:41:50

回答

0

我想通了。原來,博客中的JavaScript將文件輸入重命名爲其他東西,然後我給了它。一旦我相應地調整了我的代碼,它就起作用。我想到了之後,它被建議我輸出$ _FILES []變量。我的asyncupload.php腳本的輸出被移植回由javascript生成的隱藏輸入之一。

我只是想我會發布我的解決方案爲任何其他人與這個問題。