Error in File Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lina531
Forum Newbie
Posts: 6
Joined: Sat Nov 26, 2011 12:04 am

Error in File Upload

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Error in File Upload

Post by requinix »

What is the value of $_FILES['photo']['error']?
lina531
Forum Newbie
Posts: 6
Joined: Sat Nov 26, 2011 12:04 am

Re: Error in File Upload

Post 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!!!!!!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Error in File Upload

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Error in File Upload

Post 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!
Post Reply