Jump to content

Image uploading


CanMan2004

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
Link to comment
https://forums.phpfreaks.com/topic/9883-image-uploading/
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
Link to comment
https://forums.phpfreaks.com/topic/9883-image-uploading/#findComment-36753
Share on other sites

Archived

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

×
×
  • 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.