Jump to content

unlink and move_uploaded_file issues


mclordgt

Recommended Posts

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

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.