In a form I created for uploading images to the server, the script works excepti

The php in the script which I am creating :

[php]
$uploadedfile = $_FILES[‘file’][‘tmp_name’];
$filename = stripslashes($_FILES[‘file’][‘name’]);
$extension = getExtension($filename);
$extension = strtolower($extension);
$filetype = $_FILES[“file”][“type”] == “image/jpg” || $_FILES[“file”][“type”] == “image/jpeg” || $_FILES[“file”][“type”] == “image/pjpeg” || $extension == “JPG” || $extension == “JPEG”;

if (!$filetype) {
// Do something
}

if ($filetype) {
// Do somethings
}
[/php]

The script is doing well as far as not excepting any format but jpg files. The problem is jpg files with caps as some cameras will save the extensions as caps like JPEG or JPG. These are not being accepted. I’ve also tried the following php:

[php]
$uploadedfile = $_FILES[‘file’][‘tmp_name’];
$filename = stripslashes($_FILES[‘file’][‘name’]);
$extension = getExtension($filename);
$extension = strtolower($extension);
$filetype = $_FILES[“file”][“type”] == “image/jpg” || $_FILES[“file”][“type”] == “image/jpeg” || $_FILES[“file”][“type”] == “image/pjpeg” || $_FILES[“file”][“type”] == “image/JPG” || $_FILES[“file”][“type”] == “image/JPEG”;
[/php]

This gives the same result where it will not except jpg’s with caps. Is there a way to make it work by making the change through php? if not is there a way to get it to except the extensions with caps.

Try echoing the $extension variable to see what is being stored there. Since your using the filename as the base my guess is that your returning the entire file name not just the extension when you call the variable.

@Andrew - I did finally get it to work and the problem wasn’t the file ext. but the images being too large in size (mb/kb). I ran different tests like manually changing the ext. to lowercase but same results. I found that it was doing it to images that were over 2 mb in size. Also I found that the filetypes were overkill and causing a mixed problems as well. The php below is not how I was doing it before but it still relates.

[php]
$allowedExts = array(“image/jpeg”,“image/pjpeg”);
foreach ($allowedExts as $img_type) {
if ($img_type == $_FILES[“file”][“type”]) {
$typeOK = true;
}
[/php]

Well there you go… Simple fix.

Sponsor our Newsletter | Privacy Policy | Terms of Service