shortysbest Posted June 22, 2010 Share Posted June 22, 2010 my script for image resizing, image upload, and store information into database works great when a file is selected, however when i just click upload with no image selected it creates image filename and everything and takes up rows in database, i cannot have this because i have a code so if there isn't anything in the row for "photo/thumb" columns, it displays separate images "No image available for this item" However I cannot get it to not run the script if there is no image selected. my code is: //FILE UPLOADED //i have put had "if ($_POST) { and script below in between these brackets } //------ $myimage = new ImageSnapshot; //If loading from an uploaded file: $myimage->ImageField = $_FILES['photo']; $myimage->Width = 400; $myimage->Height = 400; $myimage->Resize = true; //if false, snapshot takes a portion from the unsized image. $myimage->ResizeScale = 100; $myimage->Position = center; $myimage->Compression = 70; $filename='itemphotos/'.rand(0,9999999).'.jpg'; //saving to a filename $myimage->SaveImageAs($filename); //FILE UPLOADED $myimage2 = new ImageSnapshot; //If loading from an uploaded file: $myimage2->ImageField = $_FILES['photo']; $myimage2->Width = 100; $myimage2->Height = 80; $myimage2->Resize = true; //if false, snapshot takes a portion from the unsized image. $myimage2->ResizeScale = 80; $myimage2->Position = center; $myimage2->Compression = 70; $filename2='itemphotos/thumbs/'.rand(0,9999999).'.jpg'; //saving to a filename $myimage2->SaveImageAs($filename2); if ($_POST['photo']!==""){ //<-------------------------this doesn't seem to be working-----the exact code worked with my previous image handling script however $name2 = ucwords(strip_tags($_POST['name'])); $description2 = ucfirst(strip_tags($_POST['description'])); $result = mysql_query("SELECT * FROM antiques ORDER By id DESC LIMIT 1"); $getid = mysql_fetch_assoc($result); $id = $getid['id']; mysql_query("UPDATE antiques SET photo='$filename', thumb='$filename2' WHERE id='$id'"); print "<script>"; print "self.location='index.php?node=antiques'"; print "</script>"; } else { echo $myimage->Err; } //END FILE UPLOADED } } Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/ Share on other sites More sharing options...
wildteen88 Posted June 22, 2010 Share Posted June 22, 2010 $_POST['photo'] should be $_FILES['photo'] if ($_POST['photo']!=="") { Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/#findComment-1075754 Share on other sites More sharing options...
shortysbest Posted June 22, 2010 Author Share Posted June 22, 2010 $_POST['photo'] should be $_FILES['photo'] if ($_POST['photo']!=="") { I had that first, however that doesn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/#findComment-1075758 Share on other sites More sharing options...
wildteen88 Posted June 22, 2010 Share Posted June 22, 2010 Oops forgot $_FILES is a multidimensional array. Use if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) { Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/#findComment-1075765 Share on other sites More sharing options...
shortysbest Posted June 22, 2010 Author Share Posted June 22, 2010 Oops forgot $_FILES is a multidimensional array. Use if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) { thanks that worked perfectly for that particular usage, however i have the same code for uploading just an image (photo gallery basically) and that code / if(!emtpy($_FILES['photo']['name'])) { that doesn't work in either the top, or the bottom where the other one is, it inserts it into the database, which isn't making much sense how it works for one but not the other? Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/#findComment-1075766 Share on other sites More sharing options...
shortysbest Posted June 22, 2010 Author Share Posted June 22, 2010 Oops forgot $_FILES is a multidimensional array. Use if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) { thanks that worked perfectly for that particular usage, however i have the same code for uploading just an image (photo gallery basically) and that code / if(!emtpy($_FILES['photo']['name'])) { that doesn't work in either the top, or the bottom where the other one is, it inserts it into the database, which isn't making much sense how it works for one but not the other? Well it works as far as not allowing uploads, but it does jus tthat, doesn't allow uploads even if you select a file.. Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/#findComment-1075779 Share on other sites More sharing options...
shortysbest Posted June 22, 2010 Author Share Posted June 22, 2010 Oops forgot $_FILES is a multidimensional array. Use if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) { thanks that worked perfectly for that particular usage, however i have the same code for uploading just an image (photo gallery basically) and that code / if(!emtpy($_FILES['photo']['name'])) { that doesn't work in either the top, or the bottom where the other one is, it inserts it into the database, which isn't making much sense how it works for one but not the other? Well it works as far as not allowing uploads, but it does jus tthat, doesn't allow uploads even if you select a file.. if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) { I guess it helps to spell empty correctly lol .. Now it works fine, Thanks, can't believe i didnt see that sooner Quote Link to comment https://forums.phpfreaks.com/topic/205584-if-no-file-selected-do-not-add-information-to-database-problem-getting-to-work/#findComment-1075787 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.