Search code examples
phpjqueryfile-uploadswfupload

what code should be in upload.php for jquery swfupload?


I just started using the jquery swfupload plugin and I have everything working besides the upload part... I don't know what to put in the upload.php file.

I get the error: Alert: {"name":"","type":"","size":""}; File: mayday-parade.png

upload.php originally had the code:

$file = $_FILES['file'];
echo '{"name":"'.$file['name'].'","type":"'.$file['type'].'","size":"'.$file['size'].'"}';

obviously this doesn't work but i added the following:

if (file_exists($_SERVER['DOCUMENT_ROOT'].'/band_photos/' . $_FILES["file"]["name"])) {
    echo 'file exists';
} else {
    $uploaddir = 'uploads/';
    $uploadfile = $uploaddir . basename($_FILES['file']['name']);
    if(move_uploaded_file($_FILES["file"]["tmp_name"], $uploadfile)) {              
        echo 'success';
} else {
    echo 'error';
}   
}

I can't seem to find out what i'm doing wrong. Can anyone help?


Solution

  • Have you changed the the file_post_name in SWFUpload's settings to "file"?

    If not, $_FILES['file'] will not return anything, because the default-name is Filedata , so use $_FILES['Filedata'] instead.