Jump to content


Photo

Image Upload Script Error


  • Please log in to reply
3 replies to this topic

#1 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 02 April 2006 - 11:16 PM

Hi all

I have a form with a file upload box, the form looks like

<form action='upload.php?action=update'>
<input name="addimage" type="file" id="addimage">
</form>

I then have the following code to upload and insert the image into the database

$sql = "SELECT * FROM details WHERE id = ".$_SESSION['ID'];
$result = mysql_query($sql);

while($row = mysql_fetch_object($result))
{
    $mid = $row -> id;
    $mimage = $row -> image;


srand(time());
$randomnum = date("sd");
$random = "$randomnum";

if ($_GET['action'] == "update")
{

if ($addimage == "") { $upfile = "mimage"; }

        if ($addimage == "")
        {        
        }
        else
    {
    $addimage_name = $random.str_replace(' ', "", $addimage_name);
    $upfile = "images/".$addimage_name;
    if (!copy($addimage, $upfile))
    {
    print "Could not move image 1 into image directory";
    exit;
    }
    createthumb($upfile,$upfile,207,'','');                    
    $upfile = $addimage_name;
    $sql_extend = $sql_extend." ,  image_1 = '$upfile'";
}

$sql ="UPDATE details SET image='$upfile' WHERE id='$id'";
@mysql_query($sql, $connection) or die(mysql_error());
}}

Everytime I try and upload a image I get

Warning: copy(C:\\Documents and Settings\\Ed\\Desktop\\image.jpg): failed to open stream: No such file or directory in /home/public_html/upload.php on line 51
Could not move image 1 into image directory

No matter how much I tinker with it

Can anyone help me?

Thanks in advance

Ed


#2 Mr.x

Mr.x
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 02 April 2006 - 11:19 PM

What code is line 51? Just for easier reference?

#3 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 02 April 2006 - 11:23 PM

[!--quoteo(post=361030:date=Apr 3 2006, 12:19 AM:name=Seanyboy)--][div class=\'quotetop\']QUOTE(Seanyboy @ Apr 3 2006, 12:19 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What code is line 51? Just for easier reference?
[/quote]

Its

if (!copy($addimage, $upfile))

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 April 2006 - 01:28 AM

forms for uploading files must have the enctype="multipart/form-data" attribute otherwise no file will be uploaded....
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users