0

是)我有的:

我正在使用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 集成并且可定制的良好多上传插件(带有简短描述),我会将您的问题标记为答案,因此数据库中的每个对象都可以拥有自己的文件夹。

请考虑您的答案,此问题的任何解决方案都会有很大帮助。

4

2 回答 2

1

您是否尝试像这里的示例一样发送带有表单数据的会话名称?

于 2013-02-06T20:14:06.687 回答
0

您应该检查$_SERVER['DOCUMENT_ROOT']返回的内容。

因为如果它返回,可以说/home/your_username/public_html/test_tool/app/webroot,我相信会发生什么,并且您正在添加/test_tool/app/webroot/uploadify/,您将永远无法上传文件。

从我的角度来看,您应该执行以下操作并保留其他所有内容:

// As long as $_SESSION['Auth']['User']['user_id'] has a value, it should work. If not, statically place a number there like /uploadify/1 to see if it works
$targetFolder = '/uploadify/' . $_SESSION['Auth']['User']['user_id']; //Relative to the root
于 2013-02-07T13:43:38.523 回答