Page 1 of 1

Error in File Upload

Posted: Thu Aug 16, 2012 8:42 am
by lina531
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

Re: Error in File Upload

Posted: Fri Aug 17, 2012 2:59 am
by requinix
What is the value of $_FILES['photo']['error']?

Re: Error in File Upload

Posted: Sat Aug 18, 2012 9:45 am
by lina531
in this code it is not required.
now, the value of $photo = file_get_contents($_FILES['photo']['tmp_name']); is blank. no photo details coming in action page, i didn't get why!!!!!!

Re: Error in File Upload

Posted: Sat Aug 18, 2012 10:31 am
by social_experiment
lina531 wrote:in this code it is not required.
Maybe but the error code will show if the file is uploaded or not, which might be causing the problem
PHP Manual wrote: Error Messages Explained
Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].

UPLOAD_ERR_OK
Value: 0; There is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZE
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

UPLOAD_ERR_PARTIAL
Value: 3; The uploaded file was only partially uploaded.

UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.

UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.

UPLOAD_ERR_CANT_WRITE
Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

UPLOAD_ERR_EXTENSION
Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.

Re: Error in File Upload

Posted: Sat Aug 18, 2012 1:03 pm
by requinix
lina531 wrote:in this code it is not required.
Error checking is not required? :lol:
lina531 wrote:no photo details coming in action page, i didn't get why!!!!!!
Because you didn't do any error checking!