开发者

Uploadify not uploading file, but indicates success

I have found some posts with the same problem I have, however, no solutions presented. I am not 100% sure what to make of this, but hope you can help.

I am attempting to use Uploadify to upload files, but the following happens:

  1. Browse for file successful (hence my 'script' and 'uploaded' attributes are correct)
  2. Progres开发者_高级运维s bar says "100%" and completes.
  3. onComplete fires saying upload successful (according to the path alerted, 'folder' attribute is correct.)
  4. If I die my script before any output, the #3 step does not happen - hence it reaches the 'script' specified. After output, the script doesn't die.
  5. FILE IS NOT FOUND IN FILESYSTEM

Not sure how this is possible - as far as I can tell, everything is correct.

Here is my code:

<script type="text/javascript"> 
    $(document).ready(function() {
        $("#addimage").validationEngine();
        $('#imagefile').uploadify({
            'uploader': "/js/uploadify/uploadify.swf",
            'fileExt': "*.jpg;*.jpeg;*.png;*.gif",
            'buttonText': "Browse...",
            'script': "/js/uploadify/uploadify.php",
            'cancelImg': "/js/uploadify/cancel.png",
            'folder': "/uploads",
            'fileDesc': 'Only *.jpg, *.jpeg, *.png, *.gif are allowed',
            'auto': true,
            'onComplete': function(event, ID, fileObj, response, data) {
                $('#name').val('Please edit this text to add a description...');
                alert('Uploaded ' + fileObj.name + ' to ' + fileObj.filePath + '.');
            }
        });        
    });
</script>

<input type="file" id="imagefile" name="imagefile" />

<?php

    if (!empty($_FILES)) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
        $targetFile =  str_replace('//', '/', $targetPath) . 'image_' . date('YmdHis') . '_' . $_FILES['Filedata']['name'];
        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    }

?>

The PHP script's only change is the name of the targetFile which I have changed, to ensure some sort of unique filename (although not foolproof) but otherwise the script is the same as released (with comments removed here for brevity purposes).

Can anybody tell my why Uploadify indicates that the file upload was successful, but no file exists in the uploads directory? I am using Windows, PHP5.3, and the uploads folder is writable (I can upload files there without Uploadify, but not with it)

Thanks in advance!

Kobus


I had similar problems on a Linux machine. It turned out that the PHP configuration on my server was the cuplrit. PHP was running in SAFE MODE. As I had uploaded the Uploadify scripts via FTP, so script files were stored in the file system with my FTP user details. Since PHP's temp folder was owned by the server root, I had a UID mismatch, i.e. the temporary upload file was attributed to root while the upload script that tried to move it was owned by the FTP user. That fragged it.

To resolve this I changed the ownership of the uploadify php script to root and from there on it worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜