jquery文件上传更改会话ID [英] Jquery File Upload change session id
问题描述
我正在使用blueimp jquery文件上传,一切正常,但我需要保存我的图片在不同的文件夹中,这取决于通过URL发送的参数,如/index.php?customer=160
< input type =hidden name =customervalue =<?php print $ _GET [id_cliente];?>>
我在表单中创建了隐藏字段,并将其保存在uploadhanndler.php中。
$ p $
/ files /'.$_ POST ['customer']。'
,这里一切正常,文件保存在我想要的文件夹中,但下次打开窗口/index.php?customer=160时,列出的文件是文件/文件夹不是文件/ 160 /文件夹或我想列出的数字。
我意识到我可以使用PHP用户目录,并保存文件在这个来自session_id()的6afa0f7338b14aeed39eb7656f364b4e这样的文件夹中,我试着用/index.php?customer=160开头的那个文件夹中的数字来改变session_id()。
session_start();
session_id($ _ GET ['customer']);
但是文件仍然保存在文件夹6afa0f7338b14aeed39eb7656f364b4e中,而当我打印session_id()时是160 。
PHP用户目录是实现我想要的一个好方法吗?我在做什么错了?
预先感谢和原谅我可怜的英语。
在UploadHandler.php中你会发现'user_dirs'选项=> false。如果你想拥有自己的用户目录而不是基于session-id的话,那么你就可以使用基于session-id的用户目录了。 ID,但是例如基于user-id(你自己定义的会话密钥),你可以按照以下方式进行:
在index.php文件中(如在jquery的Demo中所述(UploadHandler.php);
class CustomUploadHandler extends UploadHandler {
protected function get_user_id(){
@session_start();
返回$ _SESSION [*<你自己的用户ID会话密钥> *];
$ / code $ / pre
$ b $ p其次是
$ upload_handler = new CustomUploadHandler(array(
'user_dirs'=> true
));
...那就是...现在你有你自己的用户目录
I've been trying to solve this problem for days without success.
I am using blueimp Jquery File Upload and everything works fine but I need to save my pictures in different folders depending on a parameter send by url like /index.php?customer=160
<input type="hidden" name="customer" value="<?php print $_GET["id_cliente"];?>">
I created the hidden field in the form and got it in the uploadhanndler.php.
/files/'.$_POST['customer'].'
, here everything goes ok, the file is saved on the folder I wanted, but the next time I open the window /index.php?customer=160, the files listed are the files/ folder not the files/160/ folder or the number I want to list.
I realized I could use the PHP user directories, and the files are beeing saved in a folder like this 6afa0f7338b14aeed39eb7656f364b4e that comes from the session_id(), I tried then to change the session_id() with the number of the folder I want this way at the begining of the /index.php?customer=160
session_start();
session_id($_GET['customer']);
but the files are still beeing saved in folder 6afa0f7338b14aeed39eb7656f364b4e, and when I print the session_id() is 160.
PHP user directories is a good method to achieve what I want? what I am doing wrong?
Thanks in advance and excuse my poor english.
解决方案 even it has been a while since a last answer has been given to this question, I'd like to give a small update on that issue. Since version 5.17 of the jquery-file-upload library ther is a support for user-directories.
Within the UploadHandler.php you will find the option 'user_dirs' => false. Just set it to 'true' and you will have user-directories based on session-id.
If you want to have your own user-directories not based on session-ids, but e.g. based on user-id (your own defined Session key) you can proceed in the following way:
within the index.php file (as stated in the Demo of the jquery-file-upload library) you place following
right after "require('UploadHandler.php');"
class CustomUploadHandler extends UploadHandler {
protected function get_user_id() {
@session_start();
return $_SESSION[*<your own user id session key>*];
}
}
followed by:
$upload_handler = new CustomUploadHandler(array(
'user_dirs' => true
));
...and thats it...now you have your own user-directories for your uploaded files
这篇关于jquery文件上传更改会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!