mclordgt Posted February 1, 2011 Share Posted February 1, 2011 Hi guys, I'm a newbie in php programming and i would like to ask you guys about my issue... am trying to do a script that deletes a file from server and then upload an image to the server... unfortunately it doesn't work... i was able to get the upload part but after putting in the unlink() it doesn't work... the file is deleted from the server however it upload doesn't... hope you guys can assist me with this... thanks in advance... if(file_exists($file_src)){ unlink($file_src); } if(!empty($_FILES['userfile']['name'])){ //file variables $file_name = $_FILES['userfile']['name']; $temp_name = $_FILES['userfile']['tmp_name']; $file_type = $_FILES['userfile']['type']; //get extension of the file $base = basename($file_name); $extension = substr($base, strlen($base)-4, strlen($base)); //only these file types will be allowed $allowed_extensions = array(".txt", "docx", ".doc"); //check that this file type is allowed if(!in_array($extension,$allowed_extensions)){ header('Location:modify.php?action=errorupload&id='.$row['index']); } else{ move_uploaded_file($_FILES['userfile']['tmp_name'], "../files/" . $_FILES['userfile']['name']); $sql2 = "UPDATE t_board SET `writer` = '".$this->writer."', `subject` = '".$this->subject."', `message` = '".$this->message."', `filename` = '".$this->files['name']."' WHERE `index` = '".$this->id."'"; $query2 = mysql_query($sql2); $sql3 = "SELECT * FROM t_board WHERE `index` = '".$this->id."'"; $query3 = mysql_query($sql3); $row2 = mysql_fetch_array($query3); header("Location: view.php?action=edited&writer=".$row2['index']); }//in_array Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 1, 2011 Share Posted February 1, 2011 I'm not sure, but try clearstatcache() after the file_exists(): if(file_exists($file_src)){ unlink($file_src); } clearstatcache(); Quote Link to comment Share on other sites More sharing options...
mclordgt Posted February 1, 2011 Author Share Posted February 1, 2011 i have tried using clearstatcache() and still the same result... Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 1, 2011 Share Posted February 1, 2011 What errors do you get: error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
mclordgt Posted February 1, 2011 Author Share Posted February 1, 2011 i am not receiving any error message... i can only tell that it's not working coz i check the upload folder to see if the old file has been deleted and if the new file has been uploaded.. the old file gets deleted but i don't see the new file on the folder... Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 1, 2011 Share Posted February 1, 2011 If you have turned on error reporting and there is no error, then it is either not executing the move_uploaded_file() because it fails one of the if conditions in your code, or it is moving it, just not into the directory that you expect. Set some echos in your code to make sure that all of the variables are what you expect them to be. Quote Link to comment Share on other sites More sharing options...
mclordgt Posted February 1, 2011 Author Share Posted February 1, 2011 i have tried echoing all the variables and they seem to appear ok... i also removed the scripts and replaced echos' just to see if it will output the correct echo and it seems ok too... i have been stuck on this problem for two days now and can't seem to figure out what's wrong... 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.