如何更改上传目录?
我想动态更改文件上传目录
f.g:对于每个用户,将文件上传到她/他的文件夹
感谢
答案 0 :(得分:4)
您可以将目录存储在$_SESSION
变量或$_COOKIE
中,然后在文件/php/index.php中获取保存的值
$uplDir = $_SESSION["uploadDirectory"].'/;
$option = array(
/* some options */
'upload_dir' => $uplDir,
/* .... */
);
$upload_handler = new UploadHandler($option);
PS。记住开头的session_start();
答案 1 :(得分:2)
您可以通过参数在js file
中的表单数据中发送 <script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
formData: [{ name: 'custom_dir', value: '/save/file/here/' }],
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
</script>
//=========================
在上传处理程序定义中
require('UploadHandler.php');
$custom_dir = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['custom_dir'];
$upload_handler = new UploadHandler(array('upload_dir' => $custom_dir));