Page 1 of 1

Uploading image file formats - Help

Posted: Fri Feb 21, 2003 6:29 am
by mikebr
I have written a small script to upload image files to my server, most .jpg images upload without any problem, but others return empty for file_type, also all .gif files return empty also. The .JPG files came from the same camera and the gif files came from Photoshop, but should that make a difference?

Can anyone help me on this? I have posted the section of code below:

Code: Select all

<?php
$file_name = $_FILES[uploadfile][name];
$file_temp_name = $_FILES[uploadfile][tmp_name];
$file_size = $_FILES[uploadfile][size];
$file_type = $_FILES[uploadfile][type];
$file_name = trim($file_name);

include "inc_filepaths.php";
$file_path = $homedir_path."uploads/"; // Upload folder
$maxfilesize = 124000; // This must be the same as MAX_FILE_SIZE in the upload page
$uploaded = $file_name." uploaded "; // Tell the user the image status
$user_text = "";
$err = "";

# Do we have a file?
if ($file_name == "") {
$error = true;
$err = "ERROR!";
$user_text = "Upload ERROR! - No file was selected!";
} else { // If there is a file then continue

# Check the file type
switch ($file_type) {

	case "image/gif":
	$ext = ".gif";
	break;
	
	case "image/jpeg":
	$ext = ".jpg";
	break;
	
	case "image/pjpeg":
	$ext = ".jpg";
	break;
	
	default:
	$error = true;
	$err = "ERROR!";
	$user_text = "File type ($file_type) is not a .gif or .jpg format and was not uploaded.<br></br>";
	break;
	}
	
if ($error) {

$echo "$user_text";

}else{

// Upload stuff here
}
?>
:(