Jump to content


Photo

Image uploading


  • Please log in to reply
1 reply to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 17 May 2006 - 09:51 PM

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.

    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;
    }

Can anyone help?

Thanks in advance

Dave

#2 sparkwatson

sparkwatson
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 17 May 2006 - 10:57 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users