doq8211 2015-02-17 16:03
浏览 26
已采纳

PHP - blueimp自定义上传目录 - 重新加载时的空列表

i use blueimp on php. In HTML i've put a hidden input field to submit the User_ID (after login, ID of the user from DB) to the Upload Handler as $_POST value. I use the User_ID value as upload directory name to separate each users files from each other.

HTML:

    <form id="fileupload" action="server/php/index.php" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="user_file_directory" id="user_file_directory" value="<?php echo $_SESSION['user_ID']; ?>">

index.php :

<?php
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$user_filedirectory = $_POST['user_file_directory'];
$urlHolder = 'user_'.$user_filedirectory.'/';
$options = array(
                'upload_dir' => $_SERVER['DOCUMENT_ROOT'].'/ds-admin/server/php/'.$urlHolder,
                'upload_url' => './server/php/'.$urlHolder.'/',
);
if($urlHolder){
    $upload_handler = new UploadHandler($options , true , null);
}
?>

This works fine to upload something and after upload i can see the thumbnails and even enlarge them. But on a reload of the HTML the list of existing Files is empty, thou the files do still exist on server inside the right folder. On re upload of a file i will see only the new files.

How can i retrieve the content of the custom upload folder on HTML Page load? do i have to set the download-file-directory within the script part of the HTML?

  • 写回答

3条回答 默认 最新

  • dongren4147 2015-02-18 13:58
    关注

    Solution found!

    i only made the mistake not to start the session within the index.php of blueimp. after that everything woks like a flaw! Every user gets his own up/Download directory based on his User-ID from DataBase (saved in Session).

    my working index.php looks now like this:

    <?php
           /* SESSION START IS IMPORTANT   ;) */
    session_start();
    
    /*
     * jQuery File Upload Plugin PHP Example 5.14
     * 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
     */
    
    error_reporting(E_ALL | E_STRICT);
    require('UploadHandler.php');
    $user_filedirectory = $_SESSION['user_ID'];
    $urlHolder = 'user_'.$user_filedirectory.'/';
    $options = array(
                    'upload_dir' => $_SERVER['DOCUMENT_ROOT'].'/ds-admin/server/php/'.$urlHolder,
                    'upload_url' => './server/php/'.$urlHolder.'',
    );
    if($urlHolder){
        $upload_handler = new UploadHandler($options , true , null);
    } 
    ?>
    

    Lajos Arpad gave me the right hint: $_POST can't work for listing the directory content, for its value will be passed only after a Form-Action... and that is too late.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建