2 ques on image upload



Hi,
1. how do I enable multi format image upload, like user may upload jpeg,
jpg, gif files.
2. I get error 'Problem: file is not jpg image' when checking file format in
this code. Any help on why the error shows?
Code:
// $userfile is where file went on webserver
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];

// $userfile_name is original file name
$userfile_name = $HTTP_POST_FILES['userfile']['name'];

// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['userfile']['size'];

// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['userfile']['type'];

// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['userfile']['error'];
// userfile_error was introduced at PHP 4.2.0
// use this code with newer versions
if ($userfile_error > 0)
{
echo 'Problem: ';
switch ($userfile_error)
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
// end of code for 4.2.0

// one more check: does the file have the right MIME type?

if ($userfile_type != 'image/pjpeg')
{
echo 'Problem: file is not jpg image';
exit;
}

// put the file where we'd like it
$upfile = '/uploads/'.$userfile_name;

// is_uploaded_file and move_uploaded_file added at version 4.0.3
if (is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
exit;
}


echo 'File uploaded successfully<br /><br />';

// show what was uploaded
echo "$userfile_name<br />";
echo "<img src='$upfile'>";
echo '<br /><hr />';

Thanks,
Ashok


.



Relevant Pages

  • Re: Image hell(p)
    ... allow you to convert and upload almost any image to a web server. ... change image size and quality and then save as a .jpg file. ... "Steve Peterson" wrote in message ... > that won't work for a couple of reasons: image quality & possible imbedded ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: help! pics on website are coming up red "x"
    ... It depends on the choice you have for saving the image as a jpeg (jpg) in Jasc Paint Shop. ... FrontPage Resources, WebCircle, MS KB Quick Links, etc. ... I noticed when I try to upload ... I can upload it and it does come up on the webpage. ...
    (microsoft.public.frontpage.client)
  • RE: Malicious file upload in .JPG or GIF format
    ... Some checks are so bad that as long as the string includes .jpg ... Filename must end with .jpg ... Content upload to database ... If the server changes the extension to .JPG/.GIF (or only allows those ...
    (Pen-Test)
  • Re: mime types
    ... $msg = 'Problem: file is not jpg'; ... to upload a jpg using internet explorer an error is produced saying that ... bill there are other proxies not made by Microsoft Employees, ... want to allow image uploads, then make sure they are images, after all ...
    (alt.php)
  • Re: For John Inzer---->SUCCESS & another question :)
    ... Meant to say below PNG not JNG instead of JPG. ... > a collage done and tried to upload it for copies and it wouldn't upload ... >> Digital Image Support Center ...
    (microsoft.public.windowsxp.photos)