[英]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. 我正在使用blueimp jquery文件上传( https://github.com/blueimp/jQuery-File-Upload ),并且希望能够基于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.
如果网址是: http : //www.example.com/folder/ 12345678abc ,我想创建一个名为“ 12345678abc ”的文件夹,但似乎无济于事。
What i have tried so far is put this code in the constructor of UploadHandler.php : 到目前为止,我一直在尝试将这段代码放在UploadHandler.php的构造函数中:
$this->map = explode('/', $_SERVER['REQUEST_URI']);
if (!file_exists('files/'.$this->map[2].'')) { mkdir('files/'.$this->map[2].''); }
This works for a normal page, but if you put this in the UploadHandler.php file, you get the script path, not the URL. 这适用于普通页面,但是如果将其放在UploadHandler.php文件中,则会得到脚本路径,而不是URL。 So it creates a folder called ' server '.
因此,它将创建一个名为“ server ”的文件夹。 (this is the folder which holds the application)
(这是保存应用程序的文件夹)
I've got this working by setting a cookie. 我通过设置一个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: 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/",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.