Ninjakreborn Posted December 8, 2006 Share Posted December 8, 2006 Below I have the following code. It was seeming to work fine, what I need is 2 things.1. If the file was an attempted upload, it goes ahead and validates, uploads, and moves the file to the proper folder (all of that works)2. If the file was not an attempted upload, I need the if (move_uploaded_file($tmp_name1, $target1)) { $name = $_FILES['file1']['name']; }else { $name = "none"; }here, I need the $name variable to be changed to know.But it seems whether they try to upload a file ornot, it's not putting none in the database. Or atleast not all the time, is there something wrong with the logic flow of my code below?[code] <?phpif (!empty($_FILES['file1'])) { $file1 = $_FILES['file1']; $name = $_FILES['file1']['name']; $tmp_name1 = $file1['tmp_name']; $target = $docroot . "/userfiles/"; // prepare target url $target1 = $target . $name; if (file_exists($target1)) { $no = "no"; }else { if (move_uploaded_file($tmp_name1, $target1)) { $name = $_FILES['file1']['name']; }else { $name = "none"; } } } // end file working?>[/code] Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 8, 2006 Share Posted December 8, 2006 If I understand you correctly, if the user does NOT attempt to upload a value you want $name to be set to "none".the way I read it, the problem is that all of that code is only run if the first conditional (!empty($_FILES['file1'])) is true. So, $name would only be set to "none" if the user uploaded a file and the filemove failed. I think what you want is this:[code]<?phpif (!empty($_FILES['file1'])) { $file1 = $_FILES['file1']; $name = $_FILES['file1']['name']; $tmp_name1 = $file1['tmp_name']; $target = $docroot . "/userfiles/"; // prepare target url $target1 = $target . $name; if (file_exists($target1)) { $no = "no"; }else { if (move_uploaded_file($tmp_name1, $target1)) { $name = $_FILES['file1']['name']; } else { //error handling } }} else { $name = "none";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 8, 2006 Author Share Posted December 8, 2006 that didn't work either, I had to just test for "" instead when I display the pictures.FOr some reason that wasn't working, I treid that a few times. what you just showed. Quote Link to comment 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.