calvinschools Posted May 6, 2011 Share Posted May 6, 2011 Why is it that only certain images come through. I made sure all extensions were there but some jpegs come through others don't some pngs not others. Any thoughts? <?php $hostname='yobb'; $username='ybbb'; $password='Anbbbb!'; $dbname='b29'; $usertable='bbbb; $myconn=mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); if ((($_FILES["file"]["type"] =="image/gif") || ($_FILES["file"]["type"] =="image/jpeg") || ($_FILES["file"]["type"] =="image/pjpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"]< 200000)) { if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br/>"; } else { if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo "File already exists. Choose another name."; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); } } } else { echo "Invalid file"; } $path="uploads/" . $_FILES["file"]["name"]; $name=$_POST["name"]; $state=$_POST["state"]; if (!myconn) { die ('Could not connect: ' . $mysql_error()); } $db_selected=mysql_select_db('your1729',$myconn); if (!$db_selected) { die ('Can\'t use your1729 : ' . mysql_error()); } mysql_query("INSERT INTO photo(name,photopath,state) VALUES ('$name','$path','$state')") or die(mysql_error()); mysql_close($myconn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/ Share on other sites More sharing options...
Drummin Posted May 6, 2011 Share Posted May 6, 2011 I've noticed some programs save extensions in upper case as in JPEG. Possibly add those options as well? Hey I don't know. Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/#findComment-1211317 Share on other sites More sharing options...
aruns Posted May 6, 2011 Share Posted May 6, 2011 $allowed = array("jpg", "jpeg", "gif", "png"); Try this., you may avoid JPEG issues list($name, $ext) = explode(".", $_FILES['file']['name']); if(in_array(strtolower(ext), $allowed)) { // Your code here } Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/#findComment-1211329 Share on other sites More sharing options...
spiderwell Posted May 6, 2011 Share Posted May 6, 2011 and dont forget there is a file size limit in your code also. I know that sounds obvious, but sometimes the obvious things get overlooked Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/#findComment-1211356 Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2011 Share Posted May 6, 2011 The code you have, which you either got directly or indirectly from w3schools, is just about worthless. When they added the combined [type]/ check, they added it before the error check logic and now it reports an Invalid file when upload errors occur and you never see any upload error messages. A) You must always check that the upload worked before you attempt to use any of the uploaded file information. The [type] is empty and won't match anything when there is an upload error. B) You should NOT lump different validation checks into one conditional statement. This hides information about why the test failed. That code will report Invalid file when either the type or size test fails. Wouldn't it be better to output a separate message telling the visitor that the type was not supported or that the file was too large? C) As long as it is not security related, you should tell the visitor exactly why a validation test failed, including outputting the value that failed the validation test as part of the error message so that the visitor can see what the code was using that failed. If you output the actual upload [type] or information that failed a test, it will give the visitor more information about what were doing wrong (perhaps they accidentally selected a non-image file to upload) and it will give you debugging information when you are testing your code (you would be able to see the actual [type] that the browser sends.) Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/#findComment-1211360 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 Thanks guys. Really appreciate it. One more question. I'm building a website where people can upload photos to a main page where you can see all the photos and how many comments they have each have. You click on a photo to review and it opens in a new page with a comment system. Each page has its own comment system. I've been putting this together with bits and pieces and I'll finish it but I want to know of any good books or references to this specific area. I like sample scripts but would rather learn exactly whats going on so I can expand things in the future and customize mysely. Thanks Again. Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/#findComment-1211496 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 Also the images are being uploaded to the database. they are all there its just on re-entry into the table that something is happening. Sorry to be a pain but I really want to get this done. Quote Link to comment https://forums.phpfreaks.com/topic/235669-only-some-images-show-up/#findComment-1211527 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.