maxso Posted January 26, 2009 Share Posted January 26, 2009 What if statement can determine whether an upload was complete from this piece of code? <? //print_r($_POST); if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $newimage = "images/" . $imagename; //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } include("upload_form.php"); if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/ Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; That will tell you if it was uploaded right or not. Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747010 Share on other sites More sharing options...
maxso Posted January 26, 2009 Author Share Posted January 26, 2009 I tried an else statement like... $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; else{ echo "complete" } but it didnt say anything after the upload so i dont know. Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747014 Share on other sites More sharing options...
dennismonsewicz Posted January 26, 2009 Share Posted January 26, 2009 your forgot a semicolon after complete Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747017 Share on other sites More sharing options...
maxso Posted January 26, 2009 Author Share Posted January 26, 2009 In my script it has a semi-colon Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747021 Share on other sites More sharing options...
maxso Posted January 26, 2009 Author Share Posted January 26, 2009 After i upload a file, it just shows the same with no changes. Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747029 Share on other sites More sharing options...
maxso Posted January 27, 2009 Author Share Posted January 27, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747350 Share on other sites More sharing options...
void Posted January 27, 2009 Share Posted January 27, 2009 umm, why would you use empty() ? wouldn't just if($result) do the trick? Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747359 Share on other sites More sharing options...
maxso Posted January 27, 2009 Author Share Posted January 27, 2009 It checks if they have left that box empty or not. if(result) doesnt meen anything does it? If result=what? Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-747746 Share on other sites More sharing options...
maxso Posted January 27, 2009 Author Share Posted January 27, 2009 Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-748040 Share on other sites More sharing options...
work_it_work Posted January 28, 2009 Share Posted January 28, 2009 1) try this: $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(!empty($result)) { $error["result"] = "There was an error moving the uploaded file." ;} else { echo "complete"; } 2) try this: $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(!empty($result)) { $error["result"] = "There was an error moving the uploaded file." ;} else { $completemsg = "complete"; } then put this wherever you want: <?php echo $completemsg; ?> Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-748355 Share on other sites More sharing options...
kittrellbj Posted January 28, 2009 Share Posted January 28, 2009 It checks if they have left that box empty or not. if(result) doesnt meen anything does it? If result=what? I do use this kind of logic in my forms, and it works rather well. For instance, at the very top of a form validation, I use if ($_POST['name_of_form']) and that causes the if statement to fire if they press the submit button and the PHP_SELF is the method. I am not sure if it works the same with regular variables, but I would not be surprised if it did. For instance, $result = "blah" returns as "true", where as $result = "" returns as false. Null, 0, and an unset variable will return as false; however, I think empty() will give you a more absolute true/false. I am pretty sure that even if $result = 0, on a empty($result) it will return false (it has been set to something). All of the above statements should be confirmed by a more experienced coder, as I am just a bumbling fool still. Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-748363 Share on other sites More sharing options...
void Posted January 28, 2009 Share Posted January 28, 2009 It checks if they have left that box empty or not. if(result) doesnt meen anything does it? If result=what? If result=same code you had above. Assigning function to a variable and just checking whether it's empty doesn't mean anything for sure. if($result) echo 'success'; this will execute function assigned to $result and print out success. Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-748408 Share on other sites More sharing options...
maxso Posted January 28, 2009 Author Share Posted January 28, 2009 Thank you all who helped. Thank you to Work_it_work who solved it also. $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(!empty($result)) { $error["result"] = "There was an error moving the uploaded file." ;} else { echo "complete"; } Topic solved Quote Link to comment https://forums.phpfreaks.com/topic/142543-solved-image-upload/#findComment-748689 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.