jesushax Posted March 10, 2009 Share Posted March 10, 2009 hi all, below is my full code for uploading news to my site, however i keep getting the errorfiletype message, ive highlighted in red where its going wrong, i just dont know why it is anyone help? Thanks <?php function resampleimage($maxsize, $sourcefile, $destination, $imgcomp=0){ // SET THE IMAGE COMPRESSION $g_imgcomp=100-$imgcomp; // CHECK TO SEE IF THE IMAGE EXISTS FIRST if(file_exists($sourcefile)){ // FIRST WE GET THE CURRENT IMAGE SIZE $g_is=getimagesize($sourcefile); /********* CALCULATE THE WIDTH AND THE HEIGHT ***************/ // CHECK TO SEE IF THE WIDTH AND HEIGHT ARE ALREADY SMALLER THAN THE MAX SIZE if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){ // LEAVE WIDTH AND HEIGHT ALONE IF IMAGE IS SMALLER THAN MAXSIZE $new_width=$g_is[0]; $new_height=$g_is[1]; } else { // GET VALUE TO CALCULATE WIDTH AND HEIGHT $w_adjust = ($maxsize / $g_is[0]); $h_adjust = ($maxsize / $g_is[1]); // CHECK TO WHICH DIMENSION REQUIRES THE SMALLER ADJUSTMENT if($w_adjust <= $h_adjust){ // CALCULATE WIDTH AND HEIGHT IF THE WIDTH VALUE IS SMALLER $new_width=($g_is[0]*$w_adjust); $new_height=($g_is[1]*$w_adjust); } else { // CALCULATE WIDTH AND HEIGHT IF THE HEIGHT VALUE IS SMALLER $new_width=($g_is[0]*$h_adjust); $new_height=($g_is[1]*$h_adjust); } } //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER THE LAST "." ) $image_type = strrchr($sourcefile, "."); //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': $img_src = imagecreatefromjpeg($sourcefile); break; case '.jpeg': $img_src = imagecreatefromjpeg($sourcefile); break; case '.png': $img_src = imagecreatefrompng($sourcefile); break; case '.gif': $img_src = imagecreatefromgif($sourcefile); break; default: echo("Error Invalid Image Type"); die; break; } // CREATE THE TRUE COLOR IMAGE WITH NE WIDTH AND HEIGHT $img_dst=imagecreatetruecolor($new_width,$new_height); // RESAMPLE THE IMAGE TO NEW WIDTH AND HEIGHT imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]); // OUTPUT THE IMAGE AS A JPEG. // THIS CAN BE CHANGED IF YOU WANT TRANSPARENCY OR PREFER ANOTHER FORMAT. MAKE SURE YOU CHANGE HEADER ABOVE. imagejpeg($img_dst, $destination, 100); // DESTROY THE NEW IMAGE imagedestroy($img_dst); return true; } else { return false; } } switch(@$_GET["action"]) { Case "add": session_start(); include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/access.inc'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/editor_level.inc'); $absolute_path = $_SERVER['DOCUMENT_ROOT'] . "/news/uploads/";//Absolute path to where files are uploaded $thumb_path = $_SERVER['DOCUMENT_ROOT'] . "/news/uploads/thumbs/"; //Absolute path to where thumbs are to be stored if you want this $size_limit = "yes"; //do you want a size limit yes or no. $limit_size = "4000000"; //How big do you want size limit to be in bytes $limit_ext = "yes"; //do you want to limit the extensions of files uploaded $ext_count = "4"; //total number of extensions in array below $extensions = array(".jpg", ".jpeg", ".png", ".gif"); //List extensions you want files uploaded to be $extens = ''; if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) { $extens = "any extension"; } else { $ext_count2 = $ext_count+1; for($counter=0; $counter<$ext_count; $counter++) { $extens .= " $extensions[$counter]"; } } if (($limit_size == "") or ($size_limit != "yes")) { $limit_size = "any size"; } else { $limit_size .= " bytes"; $mb_size = ($limit_size/1000000); } $pichead = "<ul style=\"color:#FF0000; font-size:10px;\"><li style=\"display:inline; padding-right:10px;\">File extension must be $extens |</li>"; $pichead .="<li style=\"display:inline; padding-right:10px;\">Maximum file size is $limit_size ($mb_size MB) |</li> <li style=\"display:inline; padding-right:10px;\">No spaces in the filename</li></ul>"; $NewsTitle = mysql_escape_string($_POST["NewsTitle"]); $NewsShort = mysql_escape_string($_POST["NewsShort"]); $NewsAttach = $_FILES['NewsAttachment']['name'][0]; $NewsImage1 = $_FILES['pictures']['name'][0]; $NewsImage2 = $_FILES['pictures']['name'][1]; $NewsFull = mysql_escape_string($_POST["NewsFull"]); $NewsDate = date("Y-m-d"); if (($_POST["chkCons"]) == "1") { $Cons = "1"; } else { $Cons = "0"; } if (($_POST["chkCity"]) == "1") { $City = "1"; } else { $City = "0"; } mysql_query("INSERT INTO tblNews ( NewsTitle, NewsShort, NewsImage1, NewsAttachment, NewsFull, NewsImage2, NewsDateAdded, NewsArchive,Cons,City) Values ( '$NewsTitle', '$NewsShort', '$NewsImage1', '$NewsAttach', '$NewsFull', '$NewsImage2', '$NewsDate','0','$Cons','$City') ") or die(mysql_error()); $error=0; foreach ($_FILES["pictures"]["error"] as $key => $error) { $file_name = $_FILES["pictures"]['name'][$error]; // can call this anything you like this will take the original name $file = $_FILES["pictures"]['tmp_name'][$error]; $file_size = $_FILES["pictures"]['size'][$error]; if (($size_limit == "yes") &&($limit_size < $file_size)) { header("Location: /admin/news/edit_news.php?error=filesize"); } else { $ext = strrchr($file_name,'.'); [color=red]if (($limit_ext == "yes") && (!in_array($ext,$extensions)))[/color] { header("Location: /admin/news/edit_news.php?error=filetype"); }else{ $j = $error + 1; // first move the file to move_uploaded_file($file, $absolute_path.$file_name); // Save full size image with max width/height resampleimage("175", $absolute_path.$file_name, $absolute_path.$file_name, 0); } } $error++; } $ESQL = mysql_query("SELECT `NewsID`,`City`,`Cons`,`NewsTitle` FROM `tblNews` WHERE `NewsTitle`='$NewsTitle'") or die(mysql_error()); $ER = mysql_fetch_array($ESQL); if ($ER["Cons"] !="1" && $ER["City"] !="1") { header("Location: /admin/news/edit_news.php?ID=".$ER["NewsID"]."&action=error1"); } else{ //header("Location: /admin/news/default.php"); echo $absolute_path; echo $thumb_path; } break; default: include($_SERVER['DOCUMENT_ROOT'] . '/includes/staff_header.php'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/access.inc'); $size_limit = "yes"; //do you want a size limit yes or no. $limit_size = "4000000"; //How big do you want size limit to be in bytes $limit_ext = "yes"; //do you want to limit the extensions of files uploaded $ext_count = "4"; //total number of extensions in array below $extensions = array(".jpg", ".jpeg", ".png", ".gif"); //List extensions you want files uploaded to be $pichead = "<ul style=\"color:#FF0000; font-size:10px;\"><li style=\"display:inline; padding-right:10px;\">File extension must be $extens |</li>"; $pichead .="<li style=\"display:inline; padding-right:10px;\">Maximum file size is $limit_size ($mb_size MB) |</li> <li style=\"display:inline; padding-right:10px;\">No spaces in the filename</li></ul>"; echo"<h2>Add News</h2>\n"; include($_SERVER['DOCUMENT_ROOT'] . '/admin/news/navigation.php'); ?> <form action="<? echo $_SERVER['PHP_SELF'];?>?action=add" method="post" enctype="multipart/form-data"> <table width="100%"> <tr><td colspan="2">News Images:</td></tr> <tr><td><table> <?php $files = 3; // Change this line for the number of uploads you want to allow for($i=1; $i<=$files; $i++){ echo "<tr><td>Image $i :</td><td><input type=\"file\" name=\"pictures[]\" size=\"50\" /></td></tr>\n"; } ?> <tr> <td>Attachment : </td> <td><input name="NewsAttachment[]" type="file" id="ufile[]" size="50" /></td> </tr> </table></td> <td><? echo $pichead; ?></td></tr> <tr> <td colspan="2"><hr /></td> </tr> <tr> <td colspan="2" style="width:80%;"><span style="width:20%;">News Title: </span></td> </tr> <tr> <td colspan="2" style="width:80%;"> <input type="text" size="45" name="NewsTitle" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2">News Brief :</td> </tr> <tr> <td colspan="2"><textarea name="NewsShort" id="NewsShort" style="width:550px; height:175px;"></textarea></td> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" >News Full :</td> </tr> <tr> <td colspan="2"><textarea name="NewsFull" id="NewsFull" style="width:550px; height:175px;"></textarea></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2">Submit News to Websites</td> </tr> <tr> <td colspan="2"> <table width="50%" border="0" cellpadding="0"> <tr> <td><input name="chkCons" type="checkbox" value="1" /></td> <td>Construction Works</td> <td><input name="chkCity" type="checkbox" value="1" /></td> <td>City Works</td> </tr> </table> </td> </tr> <tr> <td colspan="2" style="height:32px;"><div style=" text-align:center"> <input type="submit" name=submit value="Add News" /> <input type="button" name="Reset" value="Cancel" alt="Cancel" onclick="document.location='/admin/news/default.php'" /> </div></td> </tr> </table> </form> <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/staff_footer.php'); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148740-solved-keep-getting-errorfiletype-message-when-type-is-jpg/ Share on other sites More sharing options...
JonnoTheDev Posted March 10, 2009 Share Posted March 10, 2009 set this to no $limit_ext = "yes"; $limit_ext = "no"; Quote Link to comment https://forums.phpfreaks.com/topic/148740-solved-keep-getting-errorfiletype-message-when-type-is-jpg/#findComment-781009 Share on other sites More sharing options...
jesushax Posted March 10, 2009 Author Share Posted March 10, 2009 yeah but then i wont be able to limit to image files, all files will be uploaded i dont want to stop the file check, just make it work cos it isnt at the moment ive tried uploading various types of jpg all of them come back error Quote Link to comment https://forums.phpfreaks.com/topic/148740-solved-keep-getting-errorfiletype-message-when-type-is-jpg/#findComment-781016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.