Jump to content


Photo

Upload file problem


  • Please log in to reply
No replies to this topic

#1 milescook

milescook
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 28 September 2006 - 12:58 PM

Ok, I'm having no end of trouble trying to upload a file to my server (using CGI and PHP).  File limits are fine, as I tried files of only a few kb. Uploads are on. I'm guessing the file is going to the server, and then getting deleted. I tried a df before, during and after the transfer, and that's why I think this.

Code is as follows for do_upload

<?php
    
$err_upload = "";
    
$image_file = $_FILES[&#8217;upload_file’];
$temporary_name = $image_file[&#8217;tmp_name’];
    
if (is_uploaded_file($temporary_name)) {
    
    // get image information
    $image_metadata = getimagesize($temporary_name);
    
    if ($image_metadata) {
        $image_width = $image_metadata[0];
        $image_height = $image_metadata[1];
        $image_type = $image_metadata[2];
    
        $save_name = $temporary_name;
    
        switch ($image_type)
        {
            case IMAGETYPE_GIF:
                $save_name .= ".gif";
                break;
            case IMAGETYPE_PNG:
                $save_name .= ".png";
                break;
            default:
                $err_upload = "Sorry… we only allow gif and png images.";
                break;
        }
    
        if (! $err_upload) {
            if (move_uploaded_file($tmp_name, "uploads/file")) {
                // you might update a database with key information here so
                // that the image can be used later
            } else {
                $err_upload = "Sorry… something went horribly awry.";
            }
        }
    }
    
} else {
    
    // some error occurred: handle it
    switch ($image_file[&#8217;error’])
    {
        case 1: // file too big (based on php.ini)
        case 2: // file too big (based on MAX_FILE_SIZE)
            $err_upload = "Sorry… image too big.";
            break;
        case 3: // file only partially uploaded
        case 4: // no file was uploaded
        case 6: // missing a temporary folder
        case 7: // failed to write to disk (only in PHP 5.1+)
            $err_upload = "Sorry… failed to upload… problem with server.";
            break;
    }
}
    
if ($err_upload) {
    print $err_upload;
} else {
    print "Success!!!";
}
?>


I have carried out the recommendations, and I have turned on error reporting. I get this:

Notice: Use of undefined constant �upload_file� - assumed '�upload_file�' in /usr/local/apache2/html/do_upload.php on line 5

Notice: Undefined index: �upload_file� in /usr/local/apache2/html/do_upload.php on line 5

Notice: Use of undefined constant �tmp_name� - assumed '�tmp_name�' in /usr/local/apache2/html/do_upload.php on line 6

Notice: Use of undefined constant �error� - assumed '�error�' in /usr/local/apache2/html/do_upload.php on line 46
Success!!!

My phpinfo is at http://apollo.cookie...net/phpinfo.php

Page is at http://apollo.cookie...pload_file.html

It says success, but the file is not in uploads!!
Please help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users