onlyican Posted November 9, 2006 Share Posted November 9, 2006 HeyI have a form, which allows someone to edit a product on there websiteOn the form, is 2 file fieldsOne for the PDFOne for the PhotoThe way I am doing this, is checking if the $_FILES is setfor example, a snippet from the form is[code]<?phpecho ".<input type='hidden' name='old_pdf' value='".$old_pdf."' />\n"."<input type='file' name='new_pdf' />\n";?>[/code]then I am checking this by doding something like[code]if(isset($_FILES["new_pdf"]["name"]){//Upload PDF$new_pdf = $_FILES["new_pdf"]["name"];}else{$new_pdf = $_POST["old_pdf"];}[/code]BUTthe form is coming up saying that $_FILES["new_pdf"]["name"]is set, although I am not trying to upload a fileAnyone know a way to check if someone is tryna upload a file or not Quote Link to comment https://forums.phpfreaks.com/topic/26687-trouble-with-_files/ Share on other sites More sharing options...
HuggieBear Posted November 9, 2006 Share Posted November 9, 2006 Try using empty() with tmp_name...[code]<?phpif (!empty($_FILES['new_pdf']['tmp_name'])){ $new_pdf = $_FILES['new_pdf']['tmp_name'];}else { $new_pdf = $_POST['old_pdf'];}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/26687-trouble-with-_files/#findComment-122089 Share on other sites More sharing options...
Cep Posted November 9, 2006 Share Posted November 9, 2006 I dont understand what your trying to do,$_FILES["new_pdf"]["name"] is just going to return the name of a file you have selected with your input if a file is selected, there is nothing to check because you are not actually doing anything to the input value once you have it. Quote Link to comment https://forums.phpfreaks.com/topic/26687-trouble-with-_files/#findComment-122091 Share on other sites More sharing options...
xyn Posted November 9, 2006 Share Posted November 9, 2006 your error is you have MISSED ')'Check : if(isset($_FILES["new_pdf"]["name"]){try this...if(isset($_FILES["new_pdf"]["name"])){//Upload PDF$new_pdf = $_FILES["new_pdf"]["name"];}else{$new_pdf = $_POST["old_pdf"];} Quote Link to comment https://forums.phpfreaks.com/topic/26687-trouble-with-_files/#findComment-122125 Share on other sites More sharing options...
onlyican Posted November 9, 2006 Author Share Posted November 9, 2006 no, I was not getting an errorI typed that out so I did not miss the any bracketsusing !empty works a dreamIm sorry, I thought I posted a thanks Quote Link to comment https://forums.phpfreaks.com/topic/26687-trouble-with-_files/#findComment-122136 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.