homepage Welcome to WebmasterWorld Guest from 54.163.139.36
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php file upload issue in IE
sneaks

5+ Year Member



 
Msg#: 3634086 posted 1:09 pm on Apr 24, 2008 (gmt 0)

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

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



 
Msg#: 3634086 posted 1:31 pm on Apr 24, 2008 (gmt 0)

what is the issue?

errors? what is the deviant behaviour?

sneaks

5+ Year Member



 
Msg#: 3634086 posted 2:46 pm on Apr 24, 2008 (gmt 0)

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

snx

sneaks

5+ Year Member



 
Msg#: 3634086 posted 6:16 pm on Apr 27, 2008 (gmt 0)

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

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



 
Msg#: 3634086 posted 8:29 pm on Apr 27, 2008 (gmt 0)

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

5+ Year Member



 
Msg#: 3634086 posted 9:07 pm on Apr 27, 2008 (gmt 0)

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

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



 
Msg#: 3634086 posted 8:15 am on Apr 28, 2008 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3634086 posted 9:24 am on Apr 28, 2008 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3634086 posted 10:20 am on Apr 28, 2008 (gmt 0)

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

5+ Year Member



 
Msg#: 3634086 posted 1:04 am on Apr 29, 2008 (gmt 0)

thanks! that pjpeg mime thing was the ticket!

Kenton

10+ Year Member



 
Msg#: 3634086 posted 1:13 am on May 12, 2008 (gmt 0)

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

5+ Year Member



 
Msg#: 3634086 posted 2:10 am on May 12, 2008 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved