0

我一直在尝试找到一个可以提供帮助的线程,并尝试了我能找到的一切来解决这个问题。

我有一个上传文件的页面,可以是任何类型,并且可以正常工作。我决定在另一个页面上使用相同的功能,但 $_FILES 数组始终为空。

形式:

 <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; 
} 

?>

echo $dirname只是显示没有文件名的文件夹。

4

2 回答 2

4

好吧,你的输入文件被称为name='profilepicture'

尝试:

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

if(move_uploaded_file($_FILES['profilepicture']['tmp_name'], $dirname)){
 header("location:profile.php"); }
于 2013-08-01T01:07:21.773 回答
2

试试这个代码:

$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; 
} 
于 2013-08-01T01:06:42.067 回答