是)我有的:
我正在使用uploadify为我编写的 Intranet 应用程序上传文件。
我需要将文件上传到属于一个用户的目录(动态创建目录)。
我明显不正确的解决方案:)
任何用户登录后,我都会为他创建一个文件夹(标题为 user_id)。
现在 uploadify.php 看起来像这样:
session_name("test_tool_cookie");
session_start();
$targetFolder = '/test_tool/app/webroot/uploadify/' . $_SESSION['Auth']['User']['user_id']; //Relative to the root
//the 3 lines above are my only change to the script
//$targetFolder = '/test_tool/app/webroot/uploadify/tmpFile'; //this was here before my changes
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('html' , 'docx', 'pdf', 'xls', 'xlsx', 'txt'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
问题
上面的脚本不会将文件上传到文件夹中(选中并且不会将文件上传到其他任何地方)。
如果我将 $targetFile 更改为静态值,它可以正常工作。
- 会话值是正确的(但被忽略)
还有什么可以回答问题
如果您建议一个易于与 cake php 集成并且可定制的良好多上传插件(带有简短描述),我会将您的问题标记为答案,因此数据库中的每个对象都可以拥有自己的文件夹。
请考虑您的答案,此问题的任何解决方案都会有很大帮助。