JJohnsenDK Posted August 29, 2007 Share Posted August 29, 2007 Hey Im wondering how i skip the $_FILES part in a form post. I need this because its not every time i need to submit with a picture in my form. Here is the code im using: <?php foreach($_FILES['image']['error'] as $k => $error){ //Tjekker for fejl, hvis igen gå videre if($_FILES['image'][$k][$error] == 0){ //Tjekker om billedet er et gyldigt billede. JPEG eller GIF billede. if($_FILES['image']['error'][$k] == "image/jpeg" || $_FILES['image']['error'][$k] == "image/pjpeg" || $_FILES['image']['error'][$k] == "image/gif"){ if(!empty($_FILES['image']['name'][$k])){ if(empty($_POST['order'])){ echo "Du skal vælge hvilket nr. billedet skal være. 1, 2 eller 3."; }else{ //Kopier billedet over i den angivne mappe copy($_FILES['image']['tmp_name'][$k], "images/products/".strtolower(get_type_name($_POST['type']))."/".strtolower(get_cat_name($_POST['cat']))."/".$_FILES['image']['name'][$k].""); echo $lan['007'].$_FILES['image']['name'][$k]; } } }else{ echo "Billedet skal være et JPEG billede."; } }else{ echo "Der skete en fejl da billedet skulle uploades. Prøv igen."; } ?> I thougth i could do this: if(empty($_FILES['image']['name'])){ then skip the hole foreach part } but this didnt help. What to do?? Link to comment https://forums.phpfreaks.com/topic/67199-how-do-i-skip-a-_files-in-a-form-post/ Share on other sites More sharing options...
Ken2k7 Posted August 29, 2007 Share Posted August 29, 2007 What type of form is it? If it's like a post where there is a box to post the image URL, then you can just set up an if statement. <form action='$_SERVER['PHP_SELF']' method='post'> <input type='text' size='20' name='picURL' /> </form> <?php $picURL = $_POST['picURL']; if ($picURL) // code to upload pic else // exit ?> Something like that? Link to comment https://forums.phpfreaks.com/topic/67199-how-do-i-skip-a-_files-in-a-form-post/#findComment-337057 Share on other sites More sharing options...
schme16 Posted August 29, 2007 Share Posted August 29, 2007 <?php if($_FILES['image']==NULL) { foreach($_FILES['image']['error'] as $k => $error){ //Tjekker for fejl, hvis igen gå videre if($_FILES['image'][$k][$error] == 0){ //Tjekker om billedet er et gyldigt billede. JPEG eller GIF billede. if($_FILES['image']['error'][$k] == "image/jpeg" || $_FILES['image']['error'][$k] == "image/pjpeg" || $_FILES['image']['error'][$k] == "image/gif"){ if(!empty($_FILES['image']['name'][$k])){ if(empty($_POST['order'])){ echo "Du skal vælge hvilket nr. billedet skal være. 1, 2 eller 3."; }else{ //Kopier billedet over i den angivne mappe copy($_FILES['image']['tmp_name'][$k], "images/products/".strtolower(get_type_name($_POST['type']))."/".strtolower(get_cat_name($_POST['cat']))."/".$_FILES['image']['name'][$k].""); echo $lan['007'].$_FILES['image']['name'][$k]; } } }else{ echo "Billedet skal være et JPEG billede."; } }else{ echo "Der skete en fejl da billedet skulle uploades. Prøv igen."; } } ?> This should work, but with no real way to test (and my poor german skills, lol), I can't be entirley sure...no reason why it won't though. Link to comment https://forums.phpfreaks.com/topic/67199-how-do-i-skip-a-_files-in-a-form-post/#findComment-337134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.