floridaflatlander Posted January 26, 2012 Share Posted January 26, 2012 I have a multipart forum that can load a photo if needed. My problem is that if no photo is selected for upload it deletes any data in the database for the current row if there is a photo. What I'm trying todo is not load upload_thumb.inc.php if no photo is selected and not run the UPDATE query // If everything's Okay Process the whole form if (empty($errors)) { //Run some of the script here if (isset($_FILES['image'])) { // Upload thumb if one is selected include_once ('../includes/upload_thumb.inc.php'); // run UPDATE query script to insert photo location and stuff in db } // run more script here } What's happening if I have a photo and don't upload another photo the guery over writes the db info for the current photo. The idea with isset($_FILES['image']) was to not load upload_thumb.inc.php and not to run the UPDATE script Thanks S Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/ Share on other sites More sharing options...
wigpip Posted January 26, 2012 Share Posted January 26, 2012 one idea what you could do is use php's getimagesize function to test more thouroughly for an image upload <?php $size = getimagesize($filename); $fp = fopen($filename, "rb"); if ($size && $fp) { // do upload here } else { // do nothings or something else } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311501 Share on other sites More sharing options...
floridaflatlander Posted January 26, 2012 Author Share Posted January 26, 2012 In my example I don't want to upload a photo $_FILES['image'] should be empty. if (isset($_FILES['image'])) { // Upload thumb if one is selected include_once ('../includes/upload_thumb.inc.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311507 Share on other sites More sharing options...
wigpip Posted January 26, 2012 Share Posted January 26, 2012 so the basic logic might be like: if getimagesize > 0 then do nothing elseif getimagesize == 0 then ok to upload to database (that's if i follow the prevailing required logic in your requirements) Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311522 Share on other sites More sharing options...
floridaflatlander Posted January 26, 2012 Author Share Posted January 26, 2012 Thanks for the reply The idea is for upload_thumb.inc.php not to be uploaded if I don't need it. I already have a jury rigged condition almost like your talking about it's if (isset($_FILES['image'])) { // Upload thumb if one is selected include_once ('../includes/upload_thumb.inc.php'); if($thumb_name) { run update query } } Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311523 Share on other sites More sharing options...
kicken Posted January 26, 2012 Share Posted January 26, 2012 if (isset($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK){ //a file was uploaded, run your include/update } That will only run the include file if a file was successfully uploaded. If you are doing additional validation checks inside your include file (file type, size, dimensions, etc) then you'll need a flag to indicate success of failure of that. Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311531 Share on other sites More sharing options...
floridaflatlander Posted January 26, 2012 Author Share Posted January 26, 2012 if (isset($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK){ //a file was uploaded, run your include/update } As a note it's include/"upload_thumb.php" not update <<< upload_thumb.php uploads a photo, does the checks, resizes it and sizes it to a file I'm not uploading a file, this is a muiltipart form that I use to edit and upload a photo if I want to, in this case I don't want to upload a file. but I do want to edit other text info. // If everything's Okay Process the whole form if (empty($errors)) { //Run some of the script here // If I decide to upload a photo with name="image" this if will execute includes/upload_thumb.inc.php *** If I don't selesct a photo this if is bypassed if (isset($_FILES['image'])) { // Upload thumb if one is selected include_once ('../includes/upload_thumb.inc.php'); // run UPDATE query script to insert photo location and stuff in db } // run more script here } I'll have to think about it because $_FILES['image']['error'] == UPLOAD_ERR_OK assumes I want to or have uploaded a photo, I think Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311538 Share on other sites More sharing options...
floridaflatlander Posted January 27, 2012 Author Share Posted January 27, 2012 Thanks I've played with - if (isset($_FILES['image']) && ($_FILES['image']['error'] == UPLOAD_ERR_OK)) - from several angles and that may have done it. I think this is like error 4, no file uploaded I'll come back tomorrow and give an update after I play with it for a while. I don't under stand why (isset($_POST['news_info'])) && (isset($_FILES['image'])) are different, but I'll address that later, anyway thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/255842-should-i-use-isset_filesimage/#findComment-1311541 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.