jquery-file-upload 插件:如何更改上传路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9398187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery-file-upload plugin : How to change the upload path?
提问by mlh
I'm trying to work with the blueimp jquery-file-upload plugin. Seems to be a good uploader, but the documentation is not helpful.
我正在尝试使用 blueimp jquery-file-upload 插件。似乎是一个很好的上传者,但文档没有帮助。
When I work with the downloadable demo script, all is ok. But, when I want to change the upload path, that doesn't work.
当我使用可下载的演示脚本时,一切正常。但是,当我想更改上传路径时,这不起作用。
I've tried to change, in index.php, the action path, like this :
我试图在 index.php 中更改操作路径,如下所示:
form id="fileupload" action="../uploads/" method="POST" enctype="multipart/form-data"
and added the folders "files" and "thumbnails" in my "uploads" folder.
并在我的“上传”文件夹中添加了文件夹“文件”和“缩略图”。
The GET call is ok, as I can see in Firebug :
GET 调用没问题,正如我在 Firebug 中看到的:
GET http://localhost/alliance_pretests/uploads/ 200 OK -8ms
But when I launch the upload action, the POST answers me (still in Firebug) :
但是当我启动上传操作时,POST 回答我(仍在 Firebug 中):
POST http://localhost/alliance_pretests/uploads/ 404 Not Found 44ms
I didn't change anything else. What did I forget ?
我没有改变其他任何东西。我忘记了什么?
Why the GET call sees the folder, but not the POST call ?
为什么 GET 调用看到文件夹,而不是 POST 调用?
Thanks in advance. Best regards.
提前致谢。此致。
回答by Roark
Although the answer @mugur supplied is correct, looking at the php class supplied with the library the first parameter in the construct method is "options" and by declaring an associative array as follows:
尽管@mugur 提供的答案是正确的,但查看随库提供的 php 类,构造方法中的第一个参数是“选项”,并声明了一个关联数组,如下所示:
$options = array('upload_dir'=>'upload/directory/of/your/choice', 'upload_url'=>'upload/directory/of/your/choice');
and passing it as the first parameter when instantiating the class:
并在实例化类时将其作为第一个参数传递:
$upload_handler = new UploadHandler($options);
Will allow you to change the upload directory every time you use the class rather than altering the source code.
将允许您在每次使用该类时更改上传目录,而不是更改源代码。
回答by Mike
The form action is not the folder where your upload folder should be. The form action is the script where the data is sent after submitting. (see more here about form actions http://www.w3schools.com/tags/att_form_action.asp)
表单操作不是您的上传文件夹所在的文件夹。表单动作是提交后发送数据的脚本。(在此处查看有关表单操作的更多信息http://www.w3schools.com/tags/att_form_action.asp)
Try finding a destination folder for uploads or look inside the script for that.
尝试查找上传的目标文件夹或查看脚本内部。
Update: after downloading the library
更新:下载库后
You should look in server/php/upload.class.php and there you have some variables with the location of the upload folder:
您应该查看 server/php/upload.class.php ,那里有一些带有上传文件夹位置的变量:
'script_url' => $this->getFullUrl().'/',
'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/',
'upload_url' => $this->getFullUrl().'/files/',
Tou should replace /files/
with your own upload folder.
Tou 应该替换/files/
为您自己的上传文件夹。