0

The past 6 days I have been busy with multiple file upload. I found uploadify and tried the free version. Didn't work out so I bought uploadifive. Still doesn't work out. Even if I change nothing to the code and just implement it as I got it, is doesn't upload the file. I don't get any errors, the uploadbar goes to 100%. And my uploadfolder stays empty. I have set chmod permissions to 755 as advised and also tried 777. I tried changing $_SERVER['DOCUMENT_ROOT'] . $targetFolder to an absolute path. When I echo Document_Root it only gives /htdocs. It doesn't matter in which folder I put it.

I'm losing my mind over this and don't know how to solve this. Below I've posted the code from index.php and uploadifive.php as I got it after download:

Index.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>

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
    move_uploaded_file($tempFile, $targetFile);
    echo 1;

} else {

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

}
}

Does anyone see what would be the problem here?

4

2 に答える 2

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 に答える