Help with upload ..

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Can anyone see why Im lossing the image type when it's renamed !


$path="uploads\". $n;
$uploaded = $_SESSION['firsttimeupload'];
if ($uploaded == "ok")
       if ($size <900000 && ereg("image", $type  ))
   $root= "http://uploads/";
   $path2=$root . $n;
   echo "<center>";
   echo "<h3>Your Image : </h3><a href=$path2>$path2</a><br /><br />";
   echo "<br>";
   echo "<img src=$path2 border='1'></img>";
   echo "<center>";
   $fp=fopen("links.text", "at");
   fwrite($fp, $path2."\n");
echo "File all ready uploaded";

     if ($size>900000)
echo "ERROR <br /> the image size is too big";

     if (!ereg("image", $type) )
echo "ERROR <br /> the file is not image<br />";


Re: Help with upload ..

Joker7 wrote:
Quoted text here. Click to load it

What are you expecting in $_FILES['user_file']['tmp_name']['type']?
There is no such array element.  You do have
$_FILES['user_file']['tmp_name'] and $_FILES['user_file']['type'].

Also, NEVER depend on the 'type' value - if it is sent, it may or may
not be accurate.  ALWAYS check the mimetype of the file on the server.
Check out exif_imagetype().

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Help with upload ..

I agree with jerry, dont use the ['type'] value to determine the image
type as it can not be relied upon. I do however find that
getImageSize() is quite useful for this purpose.


       $img_mime_type = getimagesize($_FILES[$form_fieldname]

       if(($img_mime_type[2] == IMAGETYPE_GIF) ||
         ($img_mime_type[2] == IMAGETYPE_JPEG) ||
         ($img_mime_type[2] == IMAGETYPE_PNG))

Site Timeline