For some mysterious reasons Photo upload is not working

Hi,

I am using the same Php/HTML code I have used in other pages to allow for image uploading, but somehow
it is not working on a new page I am building!

The HTML part is (in super summary format):


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
<input type="file" name="uploadedfile">
<input type="submit" name="submit_foto" value="Submit My Thumb-nail Foto" class="form_button">
</form>

The Php part that is to check & upload the images is:


if (isset($_POST['submit_foto'])) {

if (eregi('^image/p?jpeg(;.*)?$', $_FILES['uploadedfile']['type'])) {
$filetype = 'jpg';
} else if (eregi('^image/gif(;.*)?$', $_FILES['uploadedfile']['type'])) {
$filetype = 'gif';
} else {
$error = 'Thumb-nail photo has the wrong file type. Acceptable image formats are either gif or jpg.';
array_push($error_list, $error);

}//CLOSES if (eregi...........

echo 'File Type: ' . $_FILES['uploadedfile']['type'] . '<p>';

and I am getting error message that File type is not “either gif or jpg” and when I check it via the echo command I see
that the $_FILES[‘uploadedfile’][‘type’] is empty!

What is going on?
What am I missing?

ThanX,

P.S., I may have posted this message before in a wrong thread, if so please ignore that and reply here.

Are you getting anything through the $_FILES array at all?

Dump the contents out using print_r($_FILES) and see if there is anything.

One thing I did notice is that 10k is a pretty small MAX_FILE_SIZE…!


var_dump( $_FILES); 

Should always be your first port of call.

Check the return value of:


 $_FILES['uploadedfile']['error']

Very carefully. Upload error codes.

Your code should analyse this number before trying to do anything, if it is not 0 - something has gone wrong, and you could consider feeding that back to the user - or logging it somewhere.

You code is also flawed in so many ways. You should scrap it.

Hello Cups,

As per your suggestion I printed out these 2 and it is showing:

array(1) { [“uploadedfile”]=> array(5) { [“name”]=> string(20) “chilean_miners_a.jpg” [“type”]=> string(0) “” [“tmp_name”]=> string(0) “” [“error”]=> int(2) [“size”]=> int(0) } } var dump:

Files Error: 2

So what now!
ThanX.

Hello spikeZ,

No the issue is not the MAX_FILE_SIZE, since I have increased that ti much higher and still same strange Error!
Also of course is not that since the Error is happening before that as per the Error message that the File_type is missing.

So as per your and cups suggestion I have printed out the var_dump($_FILES) which you can see below.

ThanX,

I think you may want to check your MAX_FILE_SIZE hidden field again. As that is exactly what it is reporting the error to be.

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

From: http://www.php.net/manual/en/features.file-upload.errors.php

Hey ThanX.

I fixed the problem.
FYI, the problem was I was not loading the data for MAX_FILE_SIZE via the Php code that I had to do so for the rest of
the page and somehow I was missing that omission!

Thanx to all anyway.

this code i m using you can replace yours with it

it is running well

<?php include_once(“…/config/config.php”); error_reporting(0);?><?php if(isset($_REQUEST[‘s_x’])) {
if($_FILES[‘f2’][‘name’]==‘’)
{
$msg=“Select Your Image”;
}
else
{
mysql_query(“insert into portfolio(poid,p_image,p_category,p_active_ind,p_uploaddate)values(‘’,‘’,'”.$_POST[‘jumpMenu’].“',‘Y’,NOW())”) or die(mysql_error());
$filename=basename($_FILES[‘f2’][‘name’]);

$ext=substr($filename,strpos($filename,‘.’)+1);

$id=mysql_insert_id();
$newname=‘img_’.$id.‘.’.$ext;
if (($ext== “gif”)|| ($ext== “jpeg”)|| ($ext== “jpg”)|| ($ext== “png”))
{

if(move_uploaded_file ($_FILES['f2']['tmp_name'],dirname(__FILE__)."/portfolio/".$newname))

{
mysql_query(“update portfolio set p_image ='”.$newname.“‘where poid =’”.$id.“'”)or die(mysql_error());//picture update

}

}
else
{
$msg=“Upload Only Image Formatt”;
}
}
}
?>