dowm41315 2016-04-07 04:44
浏览 124
已采纳

PHP MYSQL PDO BLOB上传始终为空零字节

here is my upload code:

public function upload($id, $title, $year, $comments){
    $imagedata = fopen($_FILES['up_images']['tmp_name'], 'rb');

    $query = 'INSERT INTO uploads (uid, title, year, comments, image, image_name) VALUES (:uid, :title, :year, :comments, :image, :image_name)';
    $statement = $this->db->prepare($query);
    $statement->bindValue(':uid', $id);
    $statement->bindValue(':title', $title);
    $statement->bindValue(':year', $year);
    $statement->bindValue(':comments', $comments);
    $statement->bindValue(':image', $imagedata, PDO::PARAM_LOB);
    $statement->bindValue(':image_name', $_FILES['up_images']['name']);
    $statement->execute();

    // return $imagedata
    return $_FILES['up_images']['error'];
}

as you can see i returned ERROR and the actual IMAGE BUFFER

error = 0

returned raw buffer has all the raw image data

all my PARAMETERS pass and are successfully uploaded to the MYSQL db but the image data is NEVER passed: heres a screen of my PHPmyadmin

enter image description here

here is the table structure:

enter image description here

and here is my form:

<form action="digest.php" method="POST" id="up_form" enctype="multipart/form-data">
<input id="up_acct" name="up_acct" type="text" placeholder="Your ID" value="<?php echo $_GET['up_acct']; ?>" />
<input id="up_title" name="up_title" type="text" placeholder=" Title" value="<?php echo $_GET['up_title']; ?>" />
<input id="up_year" name="up_year" type="text" placeholder="Year" value="<?php echo $_GET['up_year']; ?>" />
<input id="up_images" name="up_images" type="file" accept=".jpg,.jpeg,.png,.gif,.svg" />
<textarea id="up_comments" name="up_comments" placeholder="COMMENTS (optional)" cols="22" rows="5"><?php echo $_GET['up_comments']; ?></textarea>
<input type="submit" name="up_submit" id="up_submit" value="UPLOAD">

the size of the image i am trying to upload is 80kb? ? ? ? ?

well below my php.ini settings.

my FILE DUMP shows all valid data including a valid temp directory and name and EVEN SIZE!

Am i missing some type of obscure configuration on mysql? php?

also - i cant store filepath name and retrieve from file system - part of a bigger project

  • 写回答

1条回答 默认 最新

  • douduidui1046 2016-04-07 04:55
    关注

    Check out the documentation page for PDO::PARAM_LOB -- bindParam (not bindValue) wants a file pointer, not the contents of the file.

    $imagedata = fopen($_FILES['up_images']['tmp_name'], 'rb');
    $statement->bindParam(':image', $imagedata, PDO::PARAM_LOB);
    

    As you mentioned, it isn't generally considered good practice to store images in the DB unless there is a very explicit reason to do so, and the downsides are well understood. If you aren't 100% sure it is necessary, it probably is not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的