jquery-file-upload plugin -如何更改/outside public_html下面的上传路径


jquery-file-upload plugin - How to change the upload path below/outside public_html?

应用程序的文件上传/下载部分受密码保护,因此只有管理员可以上传、查看和下载文件。但是它们不能驻留在public_html中,因为它们包含个人信息,并且在未登录的情况下不能访问。

我可以改变上传文件夹——但它似乎必须在public_html中,否则你不能查看你上传的文件,也不能下载它们。

这适用于web public_html目录内的"正常"操作-但是如何将'upload_url' => HTTP_SERVER设置为public_html之外?似乎有一些路径转换,所以file_upload应用程序可以提供下载链接,也许缓冲读取输出用户的浏览器?

<?php
// index.php
/*
 * jQuery File Upload Plugin PHP Example
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */
 // using jQuery-File-Upload version: 9.12.5
error_reporting(E_ALL | E_STRICT);
// UploadHandler.php and index.php remain in the default location
// jQuery-File-Upload_root/server/php/
require('UploadHandler.php');
define('DIR_DOWNLOAD', '../../_uploads/');  // the directory is in jQuery-File-Upload_root/_uploads 
define('HTTP_SERVER', 'http://localhost/jQuery-File-Upload-9.12.5/_uploads/');
$upload_handler = new UploadHandler(
    array(
        'upload_dir' => DIR_DOWNLOAD,
        'upload_url' => HTTP_SERVER,
    )
);

如果您想将文件保存在www文件夹之外,那么您的文件不能通过url直接访问。在这种情况下,您不需要为'upload_url'提供任何值。将'download_via_php'设置为true

 $options = array(
      "upload_dir" => '/home/farawayfromwww/test/',
      "download_via_php" => 1
    );
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler($options);