douxishai8552 2015-01-15 02:52
浏览 139
已采纳

尝试上传图片但不保存到服务器

something lot simpler than the usual crap I post about! Trying to create an 'Upload' button to allow user to upload pictures of themselves. The picture should then be renamed pid, and saved to the images folder..

I'm not sure why it isn't working, especially as firebug shows that fileField is being posted.

<?php 
// Parse the form data and add inventory item to the system
if (isset($_POST['picID'])) {
    $pid = $_SESSION["pid"];
    // Place image in the folder 
    $newname = "$pid.jpg";
    move_uploaded_file( $_FILES['fileField']['tmp_name'], "images/$newname");
    header("location: index.php"); 
    exit();
    }   
?>

Picture upload field

 <form method='post' enctype='multipart/form-data' action='playerparent-profile.php?pid=<?=$pid?>'>
            <td><label>
          <input type="file" name="fileField" id="fileField" />
                  <input type="hidden" name="picID" id="picID" value="<?=$pid?>">
                 <input type="submit" name="button" id="button" value="UPLOAD" />
        </label></td>
        </form>

Just trying to figure out what the heck I'm doing wrong? Any help is appreciated!

  • 写回答

2条回答 默认 最新

  • duansaxf095988 2015-01-15 03:10
    关注

    That's because this line is wrong I guess. $pid = $_SESSION["pid"]; you should use $pid = $_POST["pid"];

    your $newname variable is not getting any name it will always store .png

    hope this will help you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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,如何解決?
  • ¥15 c++头文件不能识别CDialog