samtwilliams Posted July 27, 2009 Share Posted July 27, 2009 Hi All, I have a problem with an if file exists block within my code; // PROCCESS FORM if (isset($_POST['Submit'])) { // ISSET MAIN BLOCK $uploadname = basename( $_FILES['uploaded']['name']); $target = $target . basename( $_FILES['uploaded']['name']); $clean = array(); $clean['name'] = mysql_real_escape_string($_POST['name']); $clean['type'] = mysql_real_escape_string($_POST['type']); $clean['handicap'] = mysql_real_escape_string($_POST['handicap']); $cldate = mysql_real_escape_string($_POST['closingdate']); // CONVERT DATE from dd/mm/yyyy ro yyyy-mm-dd list($d, $m, $y) = preg_split('/\//', $cldate); $mydate = sprintf('%4d-%02d-%02d', $y, $m, $d); $clean['closingdate'] = $mydate;($cldate); // START THE FORM CHECKING if (isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token']) { // TOKEN CHECK foreach($_POST as $allvalues) { // FOREACH BLOCK if($allvalues == "") { // TEST FOR BLANKS IF BLOCK $warning = 'Error: One or more of the fields are blank'; break; } else { // **FOREACH ELSE if (file_exists($target)) { // FILE CHECK IF BLOCK $warning = "The file $uploadname already exists"; } else { // **FILE CHECK ELSE if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $query_eventinsert = "INSERT INTO events (id, name, type, closingdate, handicaplimit, applicationurl) VALUES ('','" .$clean['name']."','".$clean['type']."','".$clean['closingdate']."','".$clean['handicap']."','$uploadname')"; mysql_query($query_eventinsert); $warning = 'Event added!'; } } // FILE CHECK IF BLOCK } // TEST FOR BLANKS IF BLOCK } // FOREACH BLOCK } else { // **ISSET MAIN ELSE $warning = 'Warning: You have tried to re-submit your last form entry, this would cause a duplicate!'; } // TOKEN CHECK } Even if the file does not exists the code executes the following line $warning = "The file $uploadname already exists"; Surely it should move to the else? Link to comment https://forums.phpfreaks.com/topic/167597-problem-with-if-statement/ Share on other sites More sharing options...
samtwilliams Posted July 27, 2009 Author Share Posted July 27, 2009 The if statement works by itself, but still have the problem with the rest of my code. Link to comment https://forums.phpfreaks.com/topic/167597-problem-with-if-statement/#findComment-883799 Share on other sites More sharing options...
patrickmvi Posted July 27, 2009 Share Posted July 27, 2009 What is the value of $target when it incorrectly says the file exists? Link to comment https://forums.phpfreaks.com/topic/167597-problem-with-if-statement/#findComment-883872 Share on other sites More sharing options...
samtwilliams Posted July 27, 2009 Author Share Posted July 27, 2009 <?PHP $target = "../content/events/files/"; $target = $target . basename( $_FILES['uploaded']['name']); ?> Link to comment https://forums.phpfreaks.com/topic/167597-problem-with-if-statement/#findComment-883878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.