Snorlax
Snorlax

Reputation: 53

move_uploaded_file is working in the localhost but not in the server

I'm using move_uploaded_file to transfer some files that I selected to the other folder. It's working on my localhost but not in our server. I don't know why. Here are my codes.

   <?php
     include('connect.php');
     if(isset($_POST['submit']))
     {
       $position = $_POST['position'];
       $first_name = $_POST['first_name'];
       $last_name = $_POST['last_name'];
       $contact_number = $_POST['contact_number'];
       $email = $_POST['email'];
       $status = 'NO';

       $resume = $_FILES['resume']['name'];
       $resume_tmp = $_FILES['resume']['tmp_name'];
       $ret=explode('.',$_FILES['resume']['name']);
       $file_ext=array_pop($ret);
       $extensions = array("pdf","docx");

       if(in_array($file_ext,$extensions )=== false){
        echo "<script> alert('Unsupported format')</script>";
        echo "<script>window.location='index.php';</script>";
       }
       else{    
            move_uploaded_file($resume_tmp,"resume/$resume");
            $query=$pdo->prepare("INSERT INTO                   applicants(position,first_name,last_name,contact_number,email,resume,status) VALUES (:position,:first_name,:last_name,:contact_number,:email,:resume,:status)");
            $query->bindParam(':position',$position);
            $query->bindParam(':first_name',$first_name);
            $query->bindParam(':last_name',$last_name);
            $query->bindParam(':contact_number',$contact_number);
            $query->bindParam(':email',$email);
            $query->bindParam(':resume',$resume);
            $query->bindParam(':status',$status);
            $query->execute();

            echo "<script> alert('You Successfully Applied to this Job')</script>";
            echo "<script>window.location='index.php';</script>";
      }   
      }
    ?>

Upvotes: 2

Views: 2262

Answers (2)

Kapil Kumar
Kapil Kumar

Reputation: 141

This issue can be solved by changing the folder permissions to 777. Go to your file manager and select change permissions. Make it all writable. That's all.

Upvotes: 0

munaz
munaz

Reputation: 166

First check if upload directory exist or not. and then change its permission 777 all writable.

$file = "images";
if(is_dir($file))
{
echo ("$file is a directory");
}
else
{
echo ("$file is not a directory");
}

Upvotes: 1

Related Questions