admin管理员组

文章数量:1393900

I am using uploadify and my problem is that the files are not uploading.

This is my code:

On uploadify.php I've set the root path to: /

Like this:

$targetFolder = '/'; // Relative to the root

Then the rest on the script:

<script type="text/javascript">
jQuery(document).ready(function() {


     $('#file_upload').uploadify({
        'uploader'    : '/myIncludes/UploadiftyFolder/uploadify.php',
        'swf'  : '/myIncludes/UploadiftyFolder/uploadify.swf',
        'cancelImg' : '/myIncludes/UploadiftyFolder/cancel.png',
        'folder'    : '/myUploads/UploadsDirectory/images/',
        'auto'      : true,
        'multi'         : false,
        'checkExisting' : false
      });
});
</script>

//Finally 

<input id="file_upload" type="file" name="Filedata" />
<a href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a>

When I try to upload an image it all works well (seems too) and it says - Complete ...

But nothing is being uploaded.

Any ideas?

UPDATE:

Here are my server structure paths:

My Paths:

root/myIncludes/UploadiftyFolder/  <--Here are all the uploadify files

root/myUploads/UploadsDirectory/images/  <--Here is where I need to upload

Here are my current settings on uploadify:

folder -->  '/myUploads/UploadsDirectory/images/',

and in uploadify.php --> $targetFolder = '/'; // Relative to the root

Here is the rest of the uploadify.php file ... I haven't changed anything there:

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('jpg','jpeg','gif','png'); // 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.';
    }
}

I am using uploadify and my problem is that the files are not uploading.

This is my code:

On uploadify.php I've set the root path to: /

Like this:

$targetFolder = '/'; // Relative to the root

Then the rest on the script:

<script type="text/javascript">
jQuery(document).ready(function() {


     $('#file_upload').uploadify({
        'uploader'    : '/myIncludes/UploadiftyFolder/uploadify.php',
        'swf'  : '/myIncludes/UploadiftyFolder/uploadify.swf',
        'cancelImg' : '/myIncludes/UploadiftyFolder/cancel.png',
        'folder'    : '/myUploads/UploadsDirectory/images/',
        'auto'      : true,
        'multi'         : false,
        'checkExisting' : false
      });
});
</script>

//Finally 

<input id="file_upload" type="file" name="Filedata" />
<a href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a>

When I try to upload an image it all works well (seems too) and it says - Complete ...

But nothing is being uploaded.

Any ideas?

UPDATE:

Here are my server structure paths:

My Paths:

root/myIncludes/UploadiftyFolder/  <--Here are all the uploadify files

root/myUploads/UploadsDirectory/images/  <--Here is where I need to upload

Here are my current settings on uploadify:

folder -->  '/myUploads/UploadsDirectory/images/',

and in uploadify.php --> $targetFolder = '/'; // Relative to the root

Here is the rest of the uploadify.php file ... I haven't changed anything there:

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('jpg','jpeg','gif','png'); // 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.';
    }
}
Share Improve this question edited Nov 5, 2011 at 15:57 Satch3000 asked Nov 5, 2011 at 10:48 Satch3000Satch3000 49.5k90 gold badges225 silver badges349 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

For me, the problem was in the uploadify.php file. They are using:

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

$targetFolder is defined by you at the top.

and then later:

move_uploaded_file($tempFile,$targetFile);

The default example appends the target folder to the end of $_SERVER['DOCUMENT_ROOT']. My $_SERVER['DOCUMENT_ROOT'] was actually C:\xampp\htdocs. So, to make it work your target folder would have to be:

$targetFolder = "/yourSiteFolder/wherever/your/upload/folder/is";

What I did:

Got rid of $_SERVER['DOCUMENT_ROOT'] altogether. Here is my uploadify.php file:

<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = '/sandbox/uploads'; // Relative to the root

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('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}
?>

The major change is that I've replaced this:

move_uploaded_file($tempFile,$targetFile);

with this:

move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]);

And then mented out several lines that weren't needed anymore.

And this is my check-exists.php file:

<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = 'uploads'; // Relative to the root and should match the upload folder     in the uploader script

if (file_exists("uploads/" . $_POST['filename'])) {
    echo 1;
} else {
    echo 0;
}
?>

And this is my jquery code:

$(function() {
    $("#uploadify").uploadify({
        height        : 30,
        swf           : 'uploadify/uploadify.swf',
        uploader      : 'uploadify/uploadify.php',
        width         : 120
    });
});

A note about the file structure of my site:

All the uploadify files are in the root of my site in a folder called uploadify. Within uploadify is a folder called uploads and this is where the files are uploaded.

Hope that helps.

I tried all of the other suggestions here, but none of them worked for me. Then I realized that version 3.2 of Uploadify (and maybe previous versions, too) requires a timestamp and hashed token in order to plete the upload.

First off, I had to move the script from an external JS file to my PHP file so that I could get the timestamp from PHP. (You could also do this via a hidden input value or other method, but this was the simplest way.) Then I had to add the 'formData' option to my Uploadify call along with some PHP code that gets the timestamp and hashes it with a unique salt (which you should change to a random string):

<?php $timestamp = time();?>
<script>
$('#file_upload').uploadify({
    'swf'      : '/uploadify/uploadify.swf',
    'uploader' : '/uploadify/uploadify.php',
    'formData' : {
        'timestamp' : '<?php echo $timestamp;?>',
        'token'     : '<?php echo md5("unique_salt" . $timestamp);?>'
    }
});
</script>

Although this code seems to be required in version 3.2, it is not mentioned in the implementation documentation. I had to look in the index.php file that came in the download package to find it.

Try giving "~/" before uploads folder

(Or) here is the entire script:

<script type="text/javascript">
    $(window).load(
function () {
    $("#fileInput1").uploadify({
        'uploader': 'scripts/uploadify.swf',
        'cancelImg': 'images/cancel.png',
        'buttonText': 'Browse Files',
        'script': 'UploadVB.ashx',
        'folder': 'uploads',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'queueSizeLimit': 9999,
        'simUploadLimit': 2,
        'sizeLimit': 4000000,
        'multi': true,
        'auto': true,
        'onComplete': function (event, queueID, fileObj, response, data) {
                        $("#thumbnail").append(response)

        },

        'onError': function (event, ID, fileObj, errorObj) {
            alert(errorObj.type + ' Error: ' + errorObj.info);
        }


    });
}
);
</script>

For me, all I had to do was get rid of $_SERVER['DOCUMENT_ROOT'] in the $targetPath definition. And then I also used "uploads" instead of "/uploads" as my $targetFolder.

本文标签: javascriptUploadify script no errors but no uploads eitherStack Overflow