2012-10-14 78 views
1

我在我的網站上使用「Blueimp Jquery file upload plugin」,我允許用戶在我的服務器上傳文件。我在HostGator上託管了我的網站。 問題是用戶無法上傳超過64MB /文件大小的文件,搜索後我發現HostGator已經在「php.ini」文件中將上傳文件的最大限制設置爲64MB /文件,而我無法更改此大小限制。使用「jquery文件上傳插件」將文件直接上傳到FTP服務器

但實際上我可以通過FTP直接上傳任何大小的文件,而不受任何限制。

所以,我問是否有一個解決方法,我可以用來避免此HostGator限制, 或者如果有方法允許用戶通過FTP直接上傳文件到服務器扔這個jquery插件「網絡應用程序」 。

+0

描述這個您將需要的.htaccess apache的設置沒有;你不能使用Javascript的FTP。 – SLaks

回答

2

絕對可以改變hostgator的最大文件大小設置,因爲我已經做了好幾次。

在您選擇的目錄中,創建一個.htaccess文件。在這個文件中包括php覆蓋設置。

php_value upload_max_filesize 200M 
php_value post_max_size 200M 

除非在過去幾個月內有所變化,否則此解決方法一直適用於我。

+0

感謝您的及時回覆,但這個解決方案不適合我,我只是直接在上傳文件夾中的.htaccess文件中添加了這段代碼「我不知道是否正確」,我也想問一下如何包括PHP覆蓋設置「我不明白」??請解釋更多:D – efoula

0

jupload可以通過FTP

http://jupload.sourceforge.net/

這是IMO一個確定溶液上傳。雖然並不是所有的用戶都能啓用java,但是您可以使html頁面正常降級爲http上傳,在這種情況下,只有那些想要上傳大文件的用戶纔會丟失。

或切換webhosts-另一種簡單而有效的解決方案。

-1

CAN使用FTP與「Blueimp Jquery文件上傳插件」,但它需要一些PHP編碼。不要破解UploadHandler類(file-uploads/server/php/UploadHandler.php),而應該擴展它並根據需要覆蓋函數。

require('UploadHandler.php'); 

/* 
* custom class for uploading files, simply extends the UploadHander class 
*/ 
class CustomUploadHandler extends UploadHandler { 


    /* 
    * rewreite the handle_file_upload() function to use FTP to send the files to the FTP server 
    */ 
    protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { 
     $file = new stdClass(); 
     $file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error, 
      $index, $content_range); 
     $file->size = $this->fix_integer_overflow((int)$size); 
     $file->type = $type; 
     if ($this->validate($uploaded_file, $file, $error, $index)) { 
      $this->handle_form_data($file, $index); 
      $upload_dir = $this->get_upload_path(); 
      if (!is_dir($upload_dir)) { 
       mkdir($upload_dir, $this->options['mkdir_mode'], true); 
      } 
      $file_path = $this->get_upload_path($file->name); 
      $append_file = $content_range && is_file($file_path) && 
       $file->size > $this->get_file_size($file_path); 
      if ($uploaded_file && is_uploaded_file($uploaded_file)) { 
       // multipart/formdata uploads (POST method uploads) 
       if ($append_file) { 
        file_put_contents(
         $file_path, 
         fopen($uploaded_file, 'r'), 
         FILE_APPEND 
        ); 
       } else { 
        move_uploaded_file($uploaded_file, $file_path); 
       } 
      } else { 
       // Non-multipart uploads (PUT method support) 
       file_put_contents(
        $file_path, 
        fopen('php://input', 'r'), 
        $append_file ? FILE_APPEND : 0 
       ); 
      } 
      $file_size = $this->get_file_size($file_path, $append_file); 
      if ($file_size === $file->size) { 
       $file->url = $this->get_download_url($file->name); 
       if ($this->is_valid_image_file($file_path)) { 
        $this->handle_image_file($file_path, $file); 
       } 
      } else { 
       $file->size = $file_size; 
       if (!$content_range && $this->options['discard_aborted_uploads']) { 
        unlink($file_path); 
        $file->error = $this->get_error_message('abort'); 
       } 
      } 
      $this->set_additional_file_properties($file); 
     } 

     /* 
     * now send it to the FTPserver 
     */ 
     $source_file = $file_path; // the path of the file to upload 
     $destination_file = '/your/path/' . $file->name; // the file path to upload to (must have trailing/in the path before the $file->name is appended) 

     $ftp_error = $this->ftp_upload($source_file, $destination_file); 

     if ($ftp_error != '') { 
      $file->error = $ftp_error; 
     } 

     return $file; 
    } 


    /* 
    * new function for uploading using FTP 
    */ 
    protected function ftp_upload($source_file, $destination_file) { 

     $ftp_server = 'YOUR FTP HOST NAME'; 
     $ftp_user_name = 'YOUR USER NAME'; 
     $ftp_user_pass = 'YOUR PASSWORD'; 
     $port_number = YOUR FTP PORT NUMBER; 

     $error = ''; 

     // set up basic connection 
     $conn_id = ftp_connect($ftp_server, $port_number); 
     if (!$conn_id) { 
      $error = "FTP connection has failed! Connection attempt was blocked." ; 
      return $error; 
     } 

     // login with username and password 
     $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

     // check connection 
     if (!$login_result) { 
      $error = "FTP connection has failed! "; 
      $error .= "Could not log into fpt://$ftp_server for user $ftp_user_name"; 
      return $error; 
     } 

     // upload the file 
     $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

     // check upload status 
     if (!$upload) { 
      $error = "FTP upload has failed!"; 
     } else { 
      $error = "Uploaded $source_file to $ftp_server as $destination_file"; 
     } 

     // close the FTP stream 
     ftp_close($conn_id); 

     return $error; 
    } 

} 

// options to pass to the upload handler object 
$options = [ 
    // ANY OPTIONS, SUCH AS FILE UPLOAD LOCATION 
    'upload_url' => 'fpt://YOUR-FTP-SERVER-NAME/files/', 
]; 

// finally, instantiate the new class 
$upload_handler = new CustomUploadHandler($options); 

注意,這僅僅是複製文件,通過ftp,FTP服務器後,已上載:

用以下內容替換文件的上傳/服務器/ PHP/index.php文件的內容到上傳服務器。這意味着您將擁有同一文件的兩個副本。您可以刪除最初上傳的文件,但不要做太多額外的工作,但要確保ftp操作先完成。

你需要通過Ohgodwhy