images php coding issues or problems here.
Moderators: macek, egami, gesf
by Grigory » Tue Nov 26, 2002 1:46 pm
Here is what I have to verify the image extension. I just want to make sure the file that is being uploaded in a .jpg image and not anything else. Only jpegs.
- Code: Select all
if ( ($image) && ($image != "") ) {
$type = basename($image_type);
switch ($type) {
case "jpeg":
case "jpg": $filename = "Images/$prodname.jpg";
copy ($image, $filename);
$sql = "update ctlg_products
set image = '$filename'
where prodname = $prodname";
$iresult = @mysql_query($sql);
if (!$iresult) {
echo "There was a database error when executing <PRE>$sql</PRE>";
echo mysql_error();
exit;
}
break;
default: echo "Invalid picture format: $image_type";
}
}
if (!$result)
return false;
else
return true;
}
Remember also that $image contains the path to the image on their computer. Came from a form. When I use this it always says it's not a jpeg file even when it is.
Any hints?
-
Grigory
- New php-forum User

-
- Posts: 6
- Joined: Tue Nov 26, 2002 1:40 pm
-
by WiZARD » Wed Nov 27, 2002 12:23 am
Grigory wrote:Here is what I have to verify the image extension. I just want to make sure the file that is being uploaded in a .jpg image and not anything else. Only jpegs.
- Code: Select all
if ( ($image) && ($image != "") ) {
$type = basename($image_type);
switch ($type) {
case "jpeg":
case "jpg": $filename = "Images/$prodname.jpg";
copy ($image, $filename);
$sql = "update ctlg_products
set image = '$filename'
where prodname = $prodname";
$iresult = @mysql_query($sql);
if (!$iresult) {
echo "There was a database error when executing <PRE>$sql</PRE>";
echo mysql_error();
exit;
}
break;
default: echo "Invalid picture format: $image_type";
}
}
if (!$result)
return false;
else
return true;
}
Remember also that $image contains the path to the image on their computer. Came from a form. When I use this it always says it's not a jpeg file even when it is.
Any hints?
Hi!
I'm too long time look at your code...
read man about
basename....
As you see in your code
$type = basename($image_type), variable
$type it's a not extension it's file with extension.
Interstin how you do next?:
- Code: Select all
switch ($type) {
case "jpeg":
case "jpg":
$filename = "Images/$prodname.jpg";
-

WiZARD
- Moderator

-
- Posts: 1257
- Joined: Thu Jun 20, 2002 10:14 pm
- Location: Ukraine, Crimea, Simferopol
-
Return to PHP coding => Images
Who is online
Users browsing this forum: No registered users and 2 guests