0

Uploadify keeps giving me a "HTTP error" and its starting to get pretty annoying.

Here is how I invoke uploadify:

$(document).ready( function() {
  $('#upload_image').uploadify({
    'uploader'  : '/templates/v2/uploadify/uploadify.swf',
    'script'    : '/userimages.php',
    'cancelImg' : '/templates/v2/images/cancel.png',
    'folder'    : '/images/uploads/1',
    'auto'      : true,
    'fileExt'   : '*.jpg;*.gif;*.png',
    'fileDesc'  : 'Image Files (.JPG, .GIF, .PNG)',
    'removeCompleted' : false,
    'buttonText' : 'Upload Image'
  });
});

<input id="upload_image" name="userfiles" type="file" />

PHP Code:

if (!empty($_FILES)) {
$tempFile   = $_FILES['userfile']['tmp_name'];
$targetPath = '/home/emailsms/app/images/uploads/' . $_SESSION['uid'] . '/';
$targetFile = $targetPath . $_FILES['userfile']['name'];
move_uploaded_file($tempFile, $targetFile);
switch ($_FILES['userfile']['error']) {
    case 0:
        $msg = ""; // comment this out if you don't want a message to appear on success.
        break;
    case 1:
        $msg = "The file is bigger than this PHP installation allows";
        break;
    case 2:
        $msg = "The file is bigger than this form allows";
        break;
    case 3:
        $msg = "Only part of the file was uploaded";
        break;
    case 4:
        $msg = "No file was uploaded";
        break;
    case 6:
        $msg = "Missing a temporary folder";
        break;
    case 7:
        $msg = "Failed to write file to disk";
        break;
    case 8:
        $msg = "File upload stopped by extension";
        break;
    default:
        $msg = "unknown error " . $_FILES['userfile']['error'];
        break;
}

if ($msg) {
    $stringData = "Error: " . $_FILES['userfile']['error'] . " Error Info: " . $msg;
} else {
    $stringData = "1";
} 

echo $stringData;

The PHP code works when I use a form:

<form enctype="multipart/form-data" action="/userimages" method="POST"> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form>

1 Answer 1

1

You are missing a } at the end of the file to close if (!empty($_FILES)) {

Maybe use a different IDE?

Sign up to request clarification or add additional context in comments.

3 Comments

That's only part of the code. The PHP side works when posted through a regular form.
Ah ok. I copied your code in a file and did not get the error but I did not send a file. Maybe the problem ist not in this part of the code? You could remove code block by block to find the error.
I managed to fix this. Turns out there was a problem with the code but also a problem with sessions. I have temporarily disabled sessions on the upload script but I still have to to find a permanent solution for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.