geroid Posted September 28, 2009 Share Posted September 28, 2009 Hi I've been designing a website and up til now testing it in Firefox. I'm relatively new to coding. My site works perfectly well in Firefox but there are some problems in explorer. For example, I have this image upload code. Images upload to the folder with no problems in Firefox but if I try the code in Exploror, all I get is an empty black box uploaded to the folder. It doesn't contain an image. I really need to sort out this problem. I'll include the page of code if it helps. Thanks <?php session_start(); include("config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Glór Cheatharlach</title> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/> <link rel="stylesheet" type="text/css" href="gedstyle.css"/> <? //Get the value of opt from the form. This tells us if the form has been submitted $opt=$_REQUEST['opt']; ?> </head> <BODY> <div id="fullpage"> <div id="header"> <div id="leftheader"></div> <div id="rightheader"> </div> </div> <div id="mainarea"> <div id="navcolleft"> <?php include("menu2.php"); ?> <div id="navcolbottom"> </div> </div> <div id="rightmain"> <!--Displaying the new event record that the user just entered--> <h3>You have supplied the following event information</h3><BR> <font size=2 color=green><b>You have chosen to upload images for the following event record. Please note that images must be greater than 150 px wide</b></font><BR><BR> <? //Get the record with the highest event_num and display it //This must be the new event record that admin user has just entered. $query = "select event_num, event_name, venue_name, streetaddress1, town, county, event_description_ire, event_description_eng, date_format(event_date, '%M %D, %Y ') as formatteddate, event_time from $table ORDER BY event_num DESC LIMIT 1 "; $results = mysql_query($query, $link) or die("Sorry, we could not connect to the database. Please try again"); if(mysql_num_rows($results) > 0){ while($row = mysql_fetch_object($results)){ //Format and display the event record on the webpage $_SESSION['evid'] = $row->event_num; $_SESSION['eventfulladdressconfirm'] = $row->streetaddress1.", ".$row->town.", ".$row->county; ?> <h3><?echo $row->event_name;?> </h3><? ?> <p><b>Venue:</b> <?echo $row->venue_name;?> <BR><? ?> <p><b>Address:</b> <?echo $_SESSION['eventfulladdressconfirm'] ; ?> <p><b>Description:</b> <?echo $row->event_description_ire;?> <BR><? ?> <p><b>Description:</b> <?echo $row->event_description_eng;?> <BR><? ?> <p><b>Date: </b><?echo $row->formatteddate;?> <BR><? ?> <p><b>Time: </b><?echo $row->event_time;?></p><? } } // Define the variables for use in the image script $myImage = $_FILES['fileupload']['name'];//The name of the image file $imgSrc = $_FILES['fileupload']['tmp_name'];// The server temp directory for the image file $fileType = $_FILES['fileupload']['type'];//The type of file e.g. image/jpg etc. $uniquetime =time();//Create a variable with a unique time code for the image name later //if opt is empty then the form has not been sent for the first time so display an appropriate message if ($opt =='0'){ echo "<font size=2 color=green><b>Please select browse and locate the image file on your computer</b></font><BR>"; } //If imgsrc is empty then obviously no file was chosen by the user. Output error message //Set opt to zero so the rest of the code will not be executed except to return the form to the user //We check later to see if opt is equal to '1' if($imgSrc == '' ){ echo " <BR><font size=2 color=green><b>Please browse for a file first.</font></B>"; $opt = 0; } //If the user has chosen and submitted a file if ($opt==1) { // This function simply gets the file extension of the users chosen file function getExtension($str) { $ext = pathinfo($str, PATHINFO_EXTENSION); return $ext; } //Apply the fucntion on the file name and store the file extension in the variable (extension) //Convert the extension string to lower case $extension = getExtension($myImage); $extension = strtolower($extension); //Get the width and height of the image for testing list($width,$height)=getimagesize($imgSrc); //Now we test to see if the extension is that of an image file that we accept. If not return error and form if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message if this is not a jpg, gif or png file and return the form echo '<font size=2 color="red">This is an unknown file extension! Only image types with the extension .jpg, .jpeg, .gif or .png are allowed. Please try again</font><BR>'; ?> <BR><font size=2 color="green">Please select 'Browse' to locate your image and then click 'Upload'. Please note that images must be greater than 150 px wide</font><BR> <FORM NAME="myForm" ENCTYPE="multipart/form-data" ACTION="logo.php?opt=1" METHOD="POST"> <INPUT TYPE="file" NAME="fileupload"> <TABLE><TR><TD><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Upload"></TD></form> <TD><form id="form1" method="post" action="admin.php"><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Cancel"></TD></TR></TABLE> <? //Checking to see if the image is too small (less than 150 px wide) }elseif ($width < 150){ echo "<font size=2 color=red>This image is too small for the website. Images must be at least 150 pixels in width. The image you are attempting to upload is only $width pixels wide.</font>"; ?> <BR><font size=2 color="green">Please select 'Browse' to locate your image and then click 'Upload'. Please note that images must be greater than 150 px wide</font><BR> <FORM NAME="myForm" ENCTYPE="multipart/form-data" ACTION="logo.php?opt=1" METHOD="POST"> <INPUT TYPE="file" NAME="fileupload"> <TABLE><TR><TD><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Upload"></TD></form> <TD><form id="form1" method="post" action="admin.php"><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Cancel"></TD></TR></TABLE> <? //If all is well and this is an acceptable image file then lets process it }else{ //We test to see what type of image file this is (jpg, gif or png) and apply the appropriate php function to use later If ($fileType == "image/gif") { $wtype = imagecreatefromgif($imgSrc); } If ($fileType == "image/png") { $wtype = imagecreatefrompng($imgSrc); } if ($fileType == "image/jpeg" or $fileType == "image/jpg") { $wtype = imagecreatefromjpeg($imgSrc); } //We now know we have an image file that is greater than 149 px. Now we can resize and save the image. Just save images that are between 149 and 601 pixels //However, reduce image size if larger than 600 pixels down to 600 pixels if (($width > 149) && ($width < 601)){ $newwidth = $width; }elseif ($width > 600){ $newwidth=600; } //Create proportional width/height aspect ratio or else we will get squashing and stretching $newheight= ($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$wtype,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. The resized image will be saved in the ./images/upload subdirectory. $image_number = time(); $name = $image_number. $_FILES['fileupload']['name']; $filename = "images/upload/". $image_number. $_FILES['fileupload']['name']; imagejpeg($tmp,$filename,100); //Insert the event image information into the images table where it can //be retreived by the website events page $insert = mysql_query("insert into images (event_id, category, image_path) values ('" .$_SESSION['evid']. "', 'event', '".$name."')") or die("Could not insert data because ".mysql_error()); //Now that this image is uploaded we redisplay the form ?> <BR><font size=2 color=green><b>Please select 'Browse' to locate the image on your computer and then click 'Upload'. Please note that images must be greater than 150 px wide</b></font><BR><BR> <FORM NAME="myForm" ENCTYPE="multipart/form-data" ACTION="logo.php?opt=1" METHOD="POST"> <INPUT TYPE="file" NAME="fileupload"><br><br> <TABLE><TR><TD><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Upload"></form></TD> <TD><form id="form1" method="post" action="admin.php"><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Cancel"></TD></TR></TABLE> </FORM> <BR><p><font size=2 color=green><b>Your Current Uploaded image/s are:</b></font><br><p> <?//All of the images currently uploaded for this event are pulled from the database and displayed: $query2 = "select image_id, image_path from images join $table on event_id = event_num where event_id = '".$_SESSION['evid']."' "; $results2 = mysql_query($query2, $link) or die("Sorry, we could not connect to the database. Please try again"); if(mysql_num_rows($results2) > 0){ while($row = mysql_fetch_object($results2)){ //Attempting to resize these images on the fly //Get the image name from the database $_SESSION['imgpath'] = $row->image_path; //Create whole path and name variable $imageresizelocation = "images/upload/".$_SESSION['imgpath']; //This is simply for redisplaying the sucessfully uploaded image. //Resize the image on the fly with the variable details. All images displayed at 150 pixels wide list($width1,$height1)=getimagesize($imageresizelocation); if ($height >150){ $newheight=150; $newheightdem=($height/150); $newwidth=($width/$newheightdem); }else{ $newwidth=$width; $newheight=$height; } //Display the image ?><img width="<? echo $newwidth?>" height="<? echo $newheight?>" src="<? echo $imageresizelocation?>" border= '1' bolder='0'/> <? } } } } else { //The first display of the form on page load ?> <br><br><FORM NAME="myForm" ENCTYPE="multipart/form-data" ACTION="logo.php?opt=1" METHOD="POST"> <INPUT TYPE="file" class="submitButton" NAME="fileupload"><br><br> <TABLE><TR><TD><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Upload"></form></TD> <TD><form id="form1" method="post" action="admin.php"><INPUT NAME="Submit" TYPE="submit" id="submitinput" class="highlightit" VALUE="Cancel"></TD></TR></TABLE> </FORM><!--<p><h2>Your Current Uploaded Logo</h2><br><img src="<? echo $filename?>" bolder='0'/><p>--> <? } ?> </div> <div id="float"></div> </div> </div> <div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/175772-firefoxexplorer-upload-problem-images-wont-upload-in-explorer/ Share on other sites More sharing options...
Bricktop Posted September 28, 2009 Share Posted September 28, 2009 Hi geroid, Change line 114 to read: if ($fileType == "image/jpeg" or $fileType == "image/jpg" or $fileType == "image/pjpeg") { IE uses pjpeg instead of jpeg to indentify JPEG files. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/175772-firefoxexplorer-upload-problem-images-wont-upload-in-explorer/#findComment-926251 Share on other sites More sharing options...
trq Posted September 28, 2009 Share Posted September 28, 2009 The first thing I would do would be to validate your xhtml using the validator at http://w3c.org, I can tell you now its riddled with invalid markup. Once that's done, narrow down your php code and post what is relevant. Link to comment https://forums.phpfreaks.com/topic/175772-firefoxexplorer-upload-problem-images-wont-upload-in-explorer/#findComment-926253 Share on other sites More sharing options...
geroid Posted September 28, 2009 Author Share Posted September 28, 2009 Hi Thanks for the advice. This seems to have worked for jpg files Bricktop. That's great. However, I have the same problem for png files. Can you suggest a fix for that. I allow only jpg, gif and png. Link to comment https://forums.phpfreaks.com/topic/175772-firefoxexplorer-upload-problem-images-wont-upload-in-explorer/#findComment-926272 Share on other sites More sharing options...
Bricktop Posted September 28, 2009 Share Posted September 28, 2009 Hi geroid, Change your if statement to read: If ($fileType == "image/png" or $fileType == "image/x-png") { Hope this helps. Link to comment https://forums.phpfreaks.com/topic/175772-firefoxexplorer-upload-problem-images-wont-upload-in-explorer/#findComment-926279 Share on other sites More sharing options...
geroid Posted September 28, 2009 Author Share Posted September 28, 2009 That also worked a treat Bricktop Thanks a lot Link to comment https://forums.phpfreaks.com/topic/175772-firefoxexplorer-upload-problem-images-wont-upload-in-explorer/#findComment-926289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.