Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with upload ..

Joker7
Guest
 
Posts: n/a
#1: Jun 27 '08


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

Thanks
Chris

<?
session_start();
$n=$_FILES['user_file']['name'];
$type=$_FILES['user_file']['type'];
$size=$_FILES['user_file']['size'];
$time=time();
$n=$time;
$path="uploads\\". $n;
$uploaded = $_SESSION['firsttimeupload'];
if ($uploaded == "ok")
{
if ($size <900000 && ereg("image", $type ))
{
move_uploaded_file($_FILES['user_file']['tmp_name']['type'],
$path);
$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");
fclose($fp);
session_destroy();
}
}
else
{
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 />";
}

?>



Jerry Stuckle
Guest
 
Posts: n/a
#2: Jun 28 '08

re: Help with upload ..


Joker7 wrote:
Quote:
Can anyone see why Im lossing the image type when it's renamed !
>
Thanks
Chris
>
<?
session_start();
$n=$_FILES['user_file']['name'];
$type=$_FILES['user_file']['type'];
$size=$_FILES['user_file']['size'];
$time=time();
$n=$time;
$path="uploads\\". $n;
$uploaded = $_SESSION['firsttimeupload'];
if ($uploaded == "ok")
{
if ($size <900000 && ereg("image", $type ))
{
move_uploaded_file($_FILES['user_file']['tmp_name']['type'],
$path);
$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");
fclose($fp);
session_destroy();
}
}
else
{
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 />";
}
>
?>
>
>
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.
jstucklex@attglobal.net
==================
macca
Guest
 
Posts: n/a
#3: Jul 13 '08

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.

if(is_uploaded_file($_FILES[$form_fieldname]['tmp_name'])){

$img_mime_type = getimagesize($_FILES[$form_fieldname]
['tmp_name']);

if(($img_mime_type[2] == IMAGETYPE_GIF) ||
($img_mime_type[2] == IMAGETYPE_JPEG) ||
($img_mime_type[2] == IMAGETYPE_PNG))
{
...
}
Closed Thread