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条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改