0

在过去的 6 天里,我一直忙于上传多个文件。我找到了uploadify并尝试了免费版本。没有成功,所以我买了uploadifive。还是不行。即使我没有对代码进行任何更改并且只是按照我得到的方式实现它,也不会上传文件。我没有收到任何错误,上传栏达到 100%。我的上传文件夹保持空白。我已按照建议将 chmod 权限设置为 755,还尝试了 777。我尝试更改 $_SERVER['DOCUMENT_ROOT'] 。$targetFolder 到绝对路径。当我回显 Document_Root 时,它只给出 /htdocs。我把它放在哪个文件夹中并不重要。

我对此失去了理智,不知道如何解决这个问题。下面我在下载后发布了 index.php 和 uploadifive.php 中的代码:

索引.php

<form>
    <div id="queue"></div>
    <input id="file_upload" name="file_upload" type="file" multiple="true">
    <a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>
</form>

<script type="text/javascript">
    <?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadifive({
            'auto'             : false,
            'checkScript'      : 'check-exists.php',
            'formData'         : {
                                   'timestamp' : '<?php echo $timestamp;?>',
                                   'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                                 },
            'queueID'          : 'queue',
            'uploadScript'     : 'uploadifive.php',
            'onUploadComplete' : function(file, data) { console.log(data); }
        });
    });
</script>

上传.php

// Set the uplaod directory
$uploadDir = '/uploads/';

// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile   = $_FILES['Filedata']['tmp_name'];
$uploadDir  = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
$targetFile = $uploadDir . $_FILES['Filedata']['name'];

// Validate the filetype
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

    // Save the file
    move_uploaded_file($tempFile, $targetFile);
    echo 1;

} else {

    // The file type wasn't allowed
    echo 'Invalid file type.';

}
}

有谁看到这里有什么问题?

4

2 回答 2

1

它是 $_SERVER['DOCUMENT_ROOT']。删除它并只用根文件夹替换它就可以了。

调整后的代码:

// Set the upload directory
$uploadDir = '/uploads/';

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile   = $_FILES['Filedata']['tmp_name'];
    $uploadDir  = '../htdocs'. $uploadDir;
    $targetFile = $uploadDir . $_FILES['Filedata']['name'];    

感谢你的帮助 :)

于 2013-05-08T07:33:05.850 回答
0

我写了更多的错误检查。

尝试此代码并打开您的控制台并检查uploadifive.php返回的内容。

// Set the uplaod directory
$uploadDir = '/uploads/';

// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile   = $_FILES['Filedata']['tmp_name'];
    $uploadDir  = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
    $targetFile = $uploadDir . $_FILES['Filedata']['name'];

    // Validate the filetype
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

        // Save the file
        if(move_uploaded_file($tempFile, $targetFile)) {
            echo 1;
        } else {
            echo "Cant move file on path: " . $targetFile;
        }

    } else {
        // The file type wasn't allowed
        echo 'Invalid file type.';
    }
} else { 
    echo '$_FILES is empty or token is invalid'; 
}
于 2013-05-02T20:56:35.943 回答