Jump to content

Archived

This topic is now archived and is closed to further replies.

CanMan2004

Image uploading

Recommended Posts

Hi all

recently my hosting company did a php upgrade and I have had to go through and make adjustments to the code, I believe the change was mainly the register globals change.

I have many forms, some have file and image uploads, I have one form which I cannot seem to get to work, rather than uploading an image, it just prints the word "no image", I cant see where it is having a problem. The code is.

[code]    if ($_POST['addimage'] == "") { $upfile = "no image";
    }
    if ($_POST['addimage'] == "")
    {        
    }
    else
    {
    $addimage_name = $random.str_replace(' ', "", $addimage_name);
    $upfile = "../sites/$table/images/".$addimage_name;

    if (!copy($_POST['addimage'], $upfile))
    {
    print "Could not move image";
    exit;
    }
    createthumb($upfile,$upfile,199,'','');                    
    $upfile = $addimage_name;
    }[/code]

Can anyone help?

Thanks in advance

Dave

Share this post


Link to post
Share on other sites
Hi -
I think you might want to take a look at
$_FILES

[a href=\"http://us3.php.net/manual/en/features.file-upload.php\" target=\"_blank\"]http://us3.php.net/manual/en/features.file-upload.php[/a]

It's similar to the $_POST array, but exclusively for post-file handling.

Also - I assume you have your form set to
enctype="multipart/form-data"

Also, I think the new preferred way to handle this is the php function:

move_uploaded_file($_FILES['userfile']['tmp_name'], $image_directory)
(rather than copy())
Where $image_directory is the directory you're moving it to
and 'userfile' in your case I believe would be addimage

Cheers
b

Share this post


Link to post
Share on other sites

×

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.