1

私は自分の Web サイトで「 Blueimp Jquery ファイル アップロード プラグイン」を使用しており、サーバーにファイルをアップロードできるようにユーザーに許可を与えています。HostGator で Web サイトをホストしました。問題は、ユーザーがファイルのサイズを 64MB/ファイルを超えてアップロードできないことです。検索した結果、HostGator が「php.ini」ファイルでファイルのアップロードの制限を最大 64MB/ファイルに設定していることがわかりました。このサイズ制限を変更します。

しかし、実際には、FTP を介して直接無制限に任意のサイズのファイルをアップロードできます。

したがって、この HostGator の制限を回避するために使用できる回避策があるかどうか、またはユーザーが FTP 経由でファイルをサーバーに直接アップロードできるようにする方法があるかどうかについて尋ねています。この jquery プラグイン「Web アプリケーション」をスローします。

4

3 に答える 3

2

以前に何度か行ったように、hostgator の最大ファイル サイズ設定を変更することは間違いありません。

選択したディレクトリに .htaccess ファイルを作成します。このファイルには、php の上書き設定が含まれています。

php_value upload_max_filesize 200M
php_value post_max_size 200M

ここ数か月で何かが変わっていない限り、この回避策は常にうまくいきました。

于 2012-10-14T19:55:58.097 に答える
0

jupload は ftp 経由でアップロードできます

http://jupload.sourceforge.net/

これは問題ない解決策です。すべてのユーザーが Java を有効にしているわけではありませんが、html ページを http アップロードに正常に低下させることができます。この場合、失うのは大きなファイルをアップロードしたいユーザーだけです。

またはウェブホストを切り替える - もう1つの簡単で効果的なソリューション.

于 2012-10-14T19:56:58.970 に答える
-1

「 Blueimp Jqueryファイル アップロード プラグイン」で FTP を使用できますが、PHP コーディングが必要です。UploadHandlerクラス (file-uploads/server/php/UploadHandler.php) をハックしないでください。代わりに、クラスを拡張し、必要に応じて関数をオーバーライドする必要があります。

file-uploads/server/php/index.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 サーバーにコピーするだけであることに注意してください。これは、同じファイルのコピーが 2 つあることを意味します。余分な作業をしなくても、最初にアップロードされたファイルを削除できますが、最初に ftp 操作が完了していることを確認してください。

これが必要であり、 Ohgodwhyで説明されている .htaccess Apache 設定が必要です。

于 2015-08-17T21:03:33.573 に答える