Jacques
Jacques

Reputation: 3774

$_FILES array showing up empty

I have been trying to find a thread that could help, and have tried everything I could find to fix this.

I have a page that uploads a file, can be any type, and it works. I decided to use that same functionality on another page, but the $_FILES array is always empty.

Form:

 <form method="post" class="mainForm" enctype="multipart/form-data">
     <fieldset>
        <div class="widget first">
           <div class="rowElem">
               <label for="file">Upload Profile Picture</label>
               <div class="formRight">
                   <input type="file" id="profilepicture" name="profilepicture" />
                   <button formaction="profile_pic.php"  class="greyishBtn">Upload</button>
               </div>
           </div>
      </fieldset>
  </form>

PHP:

$name_first = "John";
$name_last = "Doe";
$folder_name = $name_last . "-" . $name_first . "-ID-" . $id . "/";

$dirname = "profile/" . $folder_name;
if(!is_dir($dirname)){
    mkdir($dirname);
}

$dirname = $dirname .  $_FILES['file']['name'];

if(move_uploaded_file($_FILES['file']['tmp_name'], $dirname)){
    header("location:profile.php");
}
else{
    echo $dirname; 
} 

?>

The echo $dirname just shows the folder with no file name.

Upvotes: 0

Views: 1766

Answers (2)

Ollie Strevel
Ollie Strevel

Reputation: 871

Well, your input file is called name='profilepicture'

Try:

$dirname = $dirname .  $_FILES['profilepicture']['name'];

and

if(move_uploaded_file($_FILES['profilepicture']['tmp_name'], $dirname)){
 header("location:profile.php"); }

Upvotes: 4

ops
ops

Reputation: 2049

Try this code:

$name_first = "John";
$name_last = "Doe";
$folder_name = $name_last . "-" . $name_first . "-ID-" . $id . "/";

$dirname = "profile/" . $folder_name;
if(!is_dir($dirname)){
    mkdir($dirname);
}

$dirname = $dirname .  $_FILES['profilepicture']['name'];

if(move_uploaded_file($_FILES['profilepicture']['tmp_name'], $dirname)){
    header("location:profile.php");
}
else{
    echo $dirname; 
} 

Upvotes: 2

Related Questions