【问题标题】:jquery-file-upload plugin - How to change the upload path below/outside public_html?jquery-file-upload 插件 - 如何更改 public_html 下方/外部的上传路径?
【发布时间】:2016-09-28 23:54:06
【问题描述】:

应用程序的文件上传/下载部分受密码保护,因此只有管理员可以上传、查看和下载文件。但它们不能驻留在 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,
    )
);

【问题讨论】:

    标签: php jquery


    【解决方案1】:

    如果您想将文件保存在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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 1970-01-01
      相关资源
      最近更新 更多