我正在使用jquery文件上传
https://blueimp.github.io/jQuery-File-Upload/
我有2个表单,我想根据请求上传文件。它正确上传到特定文件夹,但是当我刷新它不会在网格中显示。
这是我的文件上传索引文件代码
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler($_REQUEST['move']);
我在uploadfile.php的构造函数中传递了这个,并修改了这样的代码
function __construct($move,$options = null, $initialize = true, $error_messages = null) {
$this->response = array();
$this->options = array(
'script_url' => $this->get_full_url().'/'.basename($this->get_server_var('SCRIPT_NAME')),
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/'.$move.'/',
'upload_url' => $this->get_full_url().'/'.$move.'/',
以下是我处理表单的Html
<form name="customupload" action="" method="post">
<input type="hidden" value="files" name="foldername">
<input type="submit" value="Background">
</form>
<form name="customupload_new" action="" method="post">
<input type="hidden" value="bc" name="foldername">
<input type="submit" value="Frame">
</form>
这里在filepload js函数中我将额外的数据作为移动参数传递
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: 'http://localhost/projectname/fileupload/',
formData: {move: '<?php if(isset($_REQUEST["foldername"])) echo $_REQUEST["foldername"];?>' }
});
所有问题都发生了,因为这个索引文件是通过ajax加载的,而且这里没有 页面加载时读取值,上传文件时读取额外参数。
如果我把静态值显示在网格中,例如。
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/myfolder',
'upload_url' => $this->get_full_url().'/myfolder',