Search Webmaster Help and Solution

[RESOLVED] Image Upload Not Working

Hi,

Im using the following function, being called from another page, to upload an image. I perform some validation against the image, to check size & file type, which all works. When I click submit on a valid file, it says the file has been uploaded, however, looking in the directory specified, the file doesnt exist!

Can anyone see what Im doing wrong?

functions.php
PHP Code: function image_upload(){
global $feedback;
$target = ../images/;
$target = $target . basename( $_FILES[uploaded][name]);
$ok=1;

//This is our size condition
if($_FILES[uploaded][size] >= 20000) {
    $feedback .= Sorry, your image is too large<br>;
    $ok=0;
}


$imageData = getimagesize($_FILES[uploaded][tmp_name]);
if($imageData == FALSE || !($imageData[2] == IMAGETYPE_GIF || $imageData[2] == IMAGETYPE_JPEG || $imageData[2] == IMAGETYPE_PNG)) {
    $feedback .= Sorry, you can only upload image files<BR>;
    $ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0) {
    $feedback .=  Sorry your file was not uploaded;
}


//If everything is ok we try to upload it
else {
    if(move_uploaded_file($_FILES[uploaded][tmp_name], $target))
{
        $feedback .=  The file . basename( $_FILES[uploaded][name]). has been uploaded;
    }
else {
        $feedback .=  Sorry, there was a problem uploading your file.;
        }
    }
}
upload.php

PHP Code: include ../include/functions.php;

if (isset($_POST[Upload])) {
    image_upload();
}
echo <form enctype=multipart/form-data action=. $PHP_SELF . method=POST>
Please choose a file: <input name=uploaded type=file /><br />
<input type=submit name=Upload value=Upload />
</form>;
Hi,

Im using the following function, being called from another page, to upload an image. I perform some validation against the image, to check size & file type, which all works. When I click submit on a valid file, it says the file has been uploaded, however, looking in the directory specified, the file doesnt exist!

Can anyone see what Im doing wrong?

functions.php
PHP Code: function image_upload(){
global $feedback;
$target = ../images/;
$target = $target . basename( $_FILES[uploaded][name]);
$ok=1;

//This is our size condition
if($_FILES[uploaded][size] >= 20000) {
    $feedback .= Sorry, your image is too large<br>;
    $ok=0;
}


$imageData = getimagesize($_FILES[uploaded][tmp_name]);
if($imageData == FALSE || !($imageData[2] == IMAGETYPE_GIF || $imageData[2] == IMAGETYPE_JPEG || $imageData[2] == IMAGETYPE_PNG)) {
    $feedback .= Sorry, you can only upload image files<BR>;
    $ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0) {
    $feedback .=  Sorry your file was not uploaded;
}


//If everything is ok we try to upload it
else {
    if(move_uploaded_file($_FILES[uploaded][tmp_name], $target))
{
        $feedback .=  The file . basename( $_FILES[uploaded][name]). has been uploaded;
    }
else {
        $feedback .=  Sorry, there was a problem uploading your file.;
        }
    }
}
upload.php

PHP Code: include ../include/functions.php;

if (isset($_POST[Upload])) {
    image_upload();
}
echo <form enctype=multipart/form-data action=. $PHP_SELF . method=POST>
Please choose a file: <input name=uploaded type=file /><br />
<input type=submit name=Upload value=Upload />
</form>;

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).