Welcome to WebmasterWorld Guest from 54.221.87.97

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php file upload issue in IE

     

sneaks

1:09 pm on Apr 24, 2008 (gmt 0)

10+ Year Member



I have been looking all over this morning for a solution to this one...

i am having problems uploading images to my server using a custom form and $_FILES but only in IE6/7. mozilla is solid...

its really basic, do an extension check and then pass the image to a resizing function....

thanks
snx

jatar_k

1:31 pm on Apr 24, 2008 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



what is the issue?

errors? what is the deviant behaviour?

sneaks

2:46 pm on Apr 24, 2008 (gmt 0)

10+ Year Member



i think it might be mime type... because i was checking jpeg... does ie upload as jpg?

snx

sneaks

6:16 pm on Apr 27, 2008 (gmt 0)

10+ Year Member



so i am still having the IE upload file issue, for some reason the file doesnt upload and then the image resize is unable to perfrom its function. the errors i get are based on the file not being found when the resize goes to handle its job. works flawless on FF...

snx

dreamcatcher

8:29 pm on Apr 27, 2008 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi sneaks,

Might be worth posting your upload code so we can see if there is a problem. Ideally you shouldn`t do the resize until the image has been confirmed as uploaded. file_exists [uk2.php.net] is an ideal function.

dc

sneaks

9:07 pm on Apr 27, 2008 (gmt 0)

10+ Year Member



function upload_image($_FILES) {

global $file_alerts;

$valid_extensions = array("jpg", "jpeg", "JPG", "JPEG", "gif", "GIF", "png", "PNG");
$file_alerts=array();

//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {

//Check if the file is JPEG / gif / png and it's size is less than ?
$filename = basename($_FILES['uploaded_file']['name']);
$ext = getExtension($filename);

if (in_array($ext, $valid_extensions) &&
($_FILES["uploaded_file"]["type"] == "image/jpeg"
$_FILES["uploaded_file"]["type"] == "image/jpg"
$_FILES["uploaded_file"]["type"] == "image/gif"
$_FILES["uploaded_file"]["type"] == "image/png")
&& ($_FILES["uploaded_file"]["size"] < 3000000)) {

//Determine the path to which we want to save this file
$newname = UPLOAD_PATH . $filename;
echo $newname;

//Check if the file with the same name exists
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
array_push ($file_alerts, "It's done! The file has been saved as: ".$newname);
return(true);
} else {
array_push ($file_alerts, "Error: A problem occurred during file upload!");
return(false);
}
} else {
array_push ($file_alerts, "Error: File ".$_FILES["uploaded_file"]["name"]." already exists");
return(false);
}

} else {
array_push ($file_alerts, "Error: Only jpg/gif/png images under 350Kb are accepted for upload");
return(false);
}
} else {
array_push ($file_alerts, "Error: No file uploaded");
return(false);
}
}

dreamcatcher

8:15 am on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Have you tried echoing the $_FILES array to see what the input is?

print_r($_FILES);

Also, one minor thing. You don`t need to pass the $_FILES array into a function. Its a superglobal array and is automatically available throughout the scope of your scripts execution.

dc

RonPK

9:24 am on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE is known to upload jpeg images with mime type
image/pjpeg
. You'll need to include that one in your check.

tomda

10:20 am on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RonPK is right, just add image/pjpeg as mime type...

Otherwise, the code looks good.

Three tiny advices:
1/ You can try to code the all thing using a class and not a function... Easier to reuse again and again. PM me if you want to see my custom class.

2/ You are checking if there is file. You should also check that path/directory exists (you never know).

3/ If it is a public upload - meaning anyone can upload - then you should limit the number of upload (per session, IP, etc.)

Tomda

sneaks

1:04 am on Apr 29, 2008 (gmt 0)

10+ Year Member



thanks! that pjpeg mime thing was the ticket!

Kenton

1:13 am on May 12, 2008 (gmt 0)

10+ Year Member



THANK YOU!1

OMG I have been having all these problems with the file downloads and couldn't even get to the point where I could isolate it to an issue only with IE.

FINALLY IT WORKS! Only taken 18 months!

sneaks

2:10 am on May 12, 2008 (gmt 0)

10+ Year Member



glad you found it useful too kenton. i love the forums here they're solid!