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

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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!