简体   繁体   中英

Blueimp Jquery File Upload - upload files in different folders

I'm working with blueimp jquery file upload ( https://github.com/blueimp/jQuery-File-Upload ) and want the ability to upload files to a folder on the basis of the URL. For example. If the url is: http://www.example.com/folder/ 12345678abc , i want to create a folder called ' 12345678abc ', but nothing seems to work.

What i have tried so far is put this code in the constructor of UploadHandler.php :

$this->map = explode('/', $_SERVER['REQUEST_URI']);
if (!file_exists('files/'.$this->map[2].'')) { mkdir('files/'.$this->map[2].''); }

Image of the script: 图片:

This works for a normal page, but if you put this in the UploadHandler.php file, you get the script path, not the URL. So it creates a folder called ' server '. (this is the folder which holds the application)

I've got this working by setting a cookie.

Controller:

setcookie("DIR", $this->uri->segment(3), 0, "/");
if (!isset($_COOKIE['DIR'])) { echo "<meta http-equiv='refresh' content='0;URL=".base_url()."upload/map/".$this->uri->segment(3)."'>"; }

UploadHandler.php:

$dir = $_COOKIE["DIR"];
if (!file_exists("../../../../resources/files/$dir")) { mkdir("../../../../resources/files/$dir"); }

Then i can set the upload dir:

'upload_dir' => "../../../../resources/files/$dir/",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM