Jump to content

Upload file problem


milescook

Recommended Posts

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

[code]<?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!!!";
}
?> [/code]


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

[code]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!!![/code]

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

Page is at http://apollo.cookieonline.net/upload_file.html

It says success, but the file is not in uploads!!
Please help!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.