donglu2008 2013-08-01 01:01
浏览 151
已采纳

$ _FILES数组显示为空

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.

  • 写回答

2条回答 默认 最新

  • douba7784 2013-08-01 01:07
    关注

    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"); }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?