Jump to content

Archived

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

Canman2005

Image Upload Script Error

Recommended Posts

Hi all

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

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

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

[code]$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());
}}[/code]

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

Share this post


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

Its

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

Share this post


Link to post
Share on other sites
forms for uploading files must have the enctype="multipart/form-data" attribute otherwise no file will be uploaded....

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.