【问题标题】:jQuery File Upload - Not showing the uploaded files after reloadjQuery File Upload - 重新加载后不显示上传的文件
【发布时间】:2014-06-01 02:17:15
【问题描述】:

所以,过去三个小时我一直在努力解决这个问题,但我觉得我离得到它还差得很远......任何帮助将不胜感激。

我已经能够设置 jQuery File Uploader 以将上传的图像保存在动态路径/url 中。一切似乎都正常,文件上传到正确的位置并显示在前端。但是,一旦重新加载页面,就没有它们的迹象。显然,这是路径/目录 url 错误。我就是不知道是什么!

这是我在 http://127.0.0.1/local/platform/backend/page-edit.php 上的 HTML 文件

<form id="fileupload" method="POST" enctype="multipart/form-data">
   ...
   <input type="hidden" name="path" value="products"><!-- Setting the directory to save the img -->
   ...
</form>

JFU的PHP文件UploadHandler.php和index.php在http://127.0.0.1/local/platform/uploads/下 index.php:

$options = array('upload_dir'=>$_POST['path'].'/'.date("Y").'/'.date("n").'/', 'upload_url'=>'../uploads/'.$_POST['path'].'/'.date("Y").'/'.date("n").'/');
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler($options);

main.js 下 http://127.0.0.1/local/platform/backend/plugins/jQuery-File-Upload-9.5.7/js/

$(function () {
'use strict';
$('#fileupload').fileupload({
    // Uncomment the following to send cross-domain cookies:
    //xhrFields: {withCredentials: true},
    url: '../uploads/'
});
...
});

正如我所说,文件上传并显示正确。但是当我刷新页面时,它们不再出现在表格中......。

【问题讨论】:

    标签: php jquery ajax file-upload jquery-file-upload


    【解决方案1】:

    找到了解决办法!

    基本上,我将我想要的值分配为页脚中的 JS 变量。然后,我在 main.js 上使用具有我需要的数据的变量,如下所示:

    $('#fileupload').fileupload({
       url: '.../uploads/index.php?page_type=' + THE_VARIABLE
    });
    

    现在,数据被传递到我的 uploads 目录下的 index.php 文件。所以,我得到查询字符串并将其发送到 UploadHandler.php:

    parse_str($_SERVER['QUERY_STRING'], $query_string);
    $options('upload_dir'=>$query_string['page_type'], 'upload_url'=>'../uploads/'.$query_string['page_type']);
    ...
    $upload_handler = new UploadHandler($potions);
    

    轰隆隆!像魅力一样工作!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2015-09-02
      • 2019-11-09
      • 2018-05-18
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      相关资源
      最近更新 更多