allaboutthekick Posted November 9, 2006 Share Posted November 9, 2006 I get this error-------Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /nfs/cust/6/85/82/728586/web/upload.php on line 67Not a JPEG file: starts with 0x47 0x49 Warning: imagecreatefromjpeg(): 'imgs/o1163112384.jpg' is not a valid JPEG file in /nfs/cust/6/85/82/728586/web/upload.php on line 67Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /nfs/cust/6/85/82/728586/web/upload.php on line 69Error Re-sampling imageWarning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /nfs/cust/6/85/82/728586/web/upload.php on line 102Not a JPEG file: starts with 0x47 0x49 Warning: imagecreatefromjpeg(): 'imgs/o1163112384.jpg' is not a valid JPEG file in /nfs/cust/6/85/82/728586/web/upload.php on line 102Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /nfs/cust/6/85/82/728586/web/upload.php on line 104Error Re-sampling imageWarning: imagedestroy(): supplied argument is not a valid Image resource in /nfs/cust/6/85/82/728586/web/upload.php on line 117But i feel its because my file checker doesnt work.........here is my script------http://pastebin.com/820708my image checker is on line 28-29 and i want to make it only allow .jpeg or .jpg images Quote Link to comment Share on other sites More sharing options...
brendandonhue Posted November 10, 2006 Share Posted November 10, 2006 You can use the results of getimagesize() to tell if the file is actually a JPEG. Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 10, 2006 Author Share Posted November 10, 2006 i dont know too much about php how would i incorporate that into the script? is it a quick add or do i need to re arrange some stuff. I didnt write this script i just downloaded it and altered it a little. Quote Link to comment Share on other sites More sharing options...
brendandonhue Posted November 10, 2006 Share Posted November 10, 2006 Change this:list($width_orig, $height_orig) = getimagesize($add);To this:list($width_orig, $height_orig, $type) = getimagesize($add);Then $type will have a value of 2 if you're working with a JPEG. Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 11, 2006 Author Share Posted November 11, 2006 how would i make it stop the script and display an error once the value of $type doesnt equal 2. Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted November 11, 2006 Share Posted November 11, 2006 by using:[code]die("Error not a jpeg");[/code]or[code]exit();[/code] Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 11, 2006 Author Share Posted November 11, 2006 so something like if(!$type == 2);die("Error not a jpeg");andhow would i make it delete the uploaded file? Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted November 11, 2006 Share Posted November 11, 2006 More like:[code]if($type != 2) die("Error not a jpeg");[/code]To delete a file, use[quote]bool unlink ( string filename [, resource context] )[/quote]Example:[code]if(unlink($strFilename) == TRUE){ echo "deleted file";}else{ echo "failed to delete file";}[/code]hth :) Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 11, 2006 Author Share Posted November 11, 2006 ok so this is what i did right here[code]if(is_uploaded_file($_FILES['userfile']['tmp_name'])){ $userfile=$_FILES['userfile']['tmp_name'];$userfile_size=$_FILES['userfile']['size'];$userfile_type=$_FILES['userfile']['type'];$userfile_name=$_FILES['userfile']['name']; list($type) = getimagesize($userfile);if($type != 2){ die("Error not a jpeg");[/code] but it always displays "error not jpeg" even when it is a jpeg.......sooooo close!!!! Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 11, 2006 Author Share Posted November 11, 2006 i did some searching and found this command[code]exif_imagetype()[/code]http://us3.php.net/manual/en/function.exif-imagetype.phpand this [code]image_type_to_extension[/code]http://us3.php.net/manual/en/function.image-type-to-extension.phpi feel that one of those codes is the one i should use but i do not know how to implement them.... Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 11, 2006 Share Posted November 11, 2006 when using the list function you must do it in order of what getimagesize() returns. getimagesize() returns the width, height, type, width and height. so to get just the type you would go like this:[code]if(is_uploaded_file($_FILES['userfile']['tmp_name'])){ $userfile=$_FILES['userfile']['tmp_name'];$userfile_size=$_FILES['userfile']['size'];$userfile_type=$_FILES['userfile']['type'];$userfile_name=$_FILES['userfile']['name']; list($width, $height, $type) = getimagesize($userfile);if($type != 2){ die("Error not a jpeg");[/code] Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 11, 2006 Author Share Posted November 11, 2006 thanks that works perfectly! Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 11, 2006 Author Share Posted November 11, 2006 One last thing.......I want this code to to report an error when someone enters a wrong password or username.[code]<?PHP $Uname=''; $Pass=''; $contents=''; if ($_REQUEST['Uname'] != "") { $Uname = $_REQUEST['Uname']; } else { die('You need both a Username and password to login'); } if ($_REQUEST['Pass'] != "") { $Pass = $_REQUEST['Pass']; } else { die('You need both a Username and password to login'); } $fp = fopen("imgs/".$Uname.".nam","rb"); $contents = fread($fp, filesize("imgs/".$Uname.".nam")); fclose($fp); $pieces = explode(" ", $contents); if ($pieces[2] == md5($Pass)) { setcookie('User',$Uname,time()+(60*60)); } else { die ('Sorry the password username combanation does not exist'); }header("Location: http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/index.php");?>[/code]the current checker is.....[code] if ($pieces[2] == md5($Pass)) { setcookie('User',$Uname,time()+(60*60)); } else { die ('Sorry the password username combanation does not exist'); }[/code]but this wont work if you cant even open the file .usr so i need something to report when the file isnt there.I feel the code should be placed right after this code[code] $fp = fopen("imgs/".$Uname.".nam","rb");[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 12, 2006 Share Posted November 12, 2006 just add this wherever:[code=php:0]if(!file_exists("imgs/".$Uname.".nam")){//code to execute if the file doesn't exist}else{//code to execute if the file exists} Quote Link to comment Share on other sites More sharing options...
allaboutthekick Posted November 12, 2006 Author Share Posted November 12, 2006 ok i implemented it here---[code]<?PHP $Uname=''; $Pass=''; $contents=''; if (!file_exists("imgs/".$Uname.".nam")){echo "Username does not exsist, please check that capslock is not on and that your entry was spelled correctly.";}else{ if ($_REQUEST['Uname'] != "") { $Uname = $_REQUEST['Uname']; } else {die('You need both a Username and password to login'); } if ($_REQUEST['Pass'] != "") { $Pass = $_REQUEST['Pass']; } else { die('You need both a Username and password to login'); } $fp = fopen("imgs/".$Uname.".nam","rb"); $contents = fread($fp, filesize("imgs/".$Uname.".nam")); fclose($fp); $pieces = explode(" ", $contents); if ($pieces[2] == md5($Pass)) {setcookie('User',$Uname,time()+(60*60)); } else {die ('Sorry the password username combanation does not exist'); }header("Location: http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/index.php");}?>[/code]but no matter what, right entry or wrong entry it states my echo. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 12, 2006 Share Posted November 12, 2006 no no no. thats looking for a file which is blank. you havnt set $Uname yet. as you can see in your code.try this:[code]<?PHP $Uname=''; $Pass=''; $contents=''; if ($_REQUEST['Uname'] != "") { $Uname = $_REQUEST['Uname']; } else { die('You need both a Username and password to login'); } if ($_REQUEST['Pass'] != "") { $Pass = $_REQUEST['Pass']; } else { die('You need both a Username and password to login'); }if(!file_exists("imgs/".$Uname.".nam")){echo "Username does not exist, please check that capslock is not on and that your entry was spelled correctly.";}else{ $fp = fopen("imgs/".$Uname.".nam","rb"); $contents = fread($fp, filesize("imgs/".$Uname.".nam")); fclose($fp); $pieces = explode(" ", $contents); if ($pieces[2] == md5($Pass)) { setcookie('User',$Uname,time()+(60*60)); } else { die ('Sorry the password username combanation does not exist'); }header("Location: http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/index.php");}?>[/code]because now $Uname is set, and we can check if the file exists. Quote Link to comment 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.