unlink and move_uploaded_file issue
Posted: Tue Feb 01, 2011 2:08 pm
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...
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...
Code: Select all
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