unlink and move_uploaded_file issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mclordgt
Forum Newbie
Posts: 1
Joined: Tue Feb 01, 2011 2:04 pm

unlink and move_uploaded_file issue

Post by mclordgt »

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

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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: unlink and move_uploaded_file issue

Post by AbraCadaver »

What errors:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply