Error in File Upload

Hi,

Can anyone help for this. In my project i uploaded files by using this query

@list(, , $imtype, ) = getimagesize($_FILES[‘photo’][‘tmp_name’]);
// Get image type.
// We use @ to omit errors
if ($imtype == 3) // cheking image type
$photo_ext=“png”; // to use it later in HTTP headers
elseif ($imtype == 2)
$photo_ext=“jpeg”;
elseif ($imtype == 1)
$photo_ext=“gif”;

	$photo = file_get_contents($_FILES['photo']['tmp_name']);
			 $photo = mysql_real_escape_string($photo);

if($photo!=‘’){ $db->execute(“UPDATE emp_personal SET photo=‘$photo’, photo_ext=‘$photo_ext’ WHERE emp_id =‘$emp_id’”);}

Upto some days it worked but, now it didn’t give error and files are not uploaded. In this code files are not transfer to any folder only insert into database and accessed by some php code.

why this problem comes, any limit in saving or what reason can anyone suggest??

Thanks in advance

The code you posted will insert the actual image into a database but won’t save the image file anywhere. Is there more that you haven’t shown? If they’re being inserted into the database OK then the upload is working, at least partially.

For viewing the images which is uploaded by this code:

<img style=“margin:0 10px;” src=‘photoview.php?show=<?php echo $emp_id; ?>’ height=“120” alt=’ ’ />

if (isset($_GET[‘show’]))
{
$emp_id = intval($_GET[‘show’]);

$result = mysql_query("SELECT photo_ext, photo
                         FROM `emp_personal`
                        WHERE emp_id=$emp_id LIMIT 1");

list($photo_ext, $photo) = mysql_fetch_row($result);

$photo_check=$photo;
if($photo_check!=‘’){

// outputing HTTP headers
header('Content-Length: '.strlen($photo));
header(“Content-type: image/{$photo_ext}”);
//echo $photo;
echo $photo;
}else {

	 $u="User.png";
 //header('Content-Length: '.strlen($photo));

header(“Content-type: image/png”);

echo file_get_contents(“images/$u”);

}

//exit();
}

but i don’t know for which reason i didn’t see the photos.
can u say that on which reasons a file can’t upload?? i didn’t get the reason, when i upload a image it didn’t see on action page…

OK, I think I see what you mean. The first thing I would do is output $_FILES on your upload page to see what’s there:

print_r($_FILES);

It sounds like the upload is failing for some reason but by default it won’t notify you. $_FILES will show you if there are any errors, and if not it might give a clue as to what is happening.

From there I would output the content of $imtype and $photo to see how far it is getting before something fails.

thank u for the reply.

hi

ya right when i print the $FILES it shows me the

Array ( [photo] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [signature] => Array ( [name] => 1.jpg [type] => [tmp_name] => [error] => 6 [size] => 0 ) )

$signature = mysql_real_escape_string($signature);
this line comes before print_r($_FILES); but, when i echo the signature variable it shows blank… how it can possible…

i didn’t understand that, why the problems come… can u help me for this.

thanks it solved…

I just removed the tmp folder. When i create the folder it works…

Always, without fail, the first thing to check is the error number.

In your case:


 [error] => 6

Should be error => 0, read the error codes page.

pseudocode handling should be something like:



if( $array['error'] > 0 ){

// something went wrong, tell the user or log the error

} else {

// carry on with the operation

}


Glad you got it solved though …