droirqk4795 2017-04-20 18:15
浏览 11
已采纳

将图像上传到MySQL,无穷无尽的错误

I've spent most of my day working on this image uploader, after browsing and visitng many many threads and forums I've found several solutions to my problems however I am now at the point where if I try a different solution, something else breaks.

What I've got so far:

 <form action="create.php" method="post" enctype="multipart/form-data">

    Select File
    <input type="file" name="upload">

    <input type="submit" name="submit" value="Upload" />
    <input type="text" name="title" placeholder="Title" />
    <input type="text" name="description" placeholder="Description" />
    <input type="text" name="category" placeholder="Category" />

</form>
<?php
$conn = new PDO ("mysql:host=localhost;dbname=project;", "root", "0612733771Aa");

Full PHP is here, couldnt figure the formatting

https://pastebin.com/LGeuzLRH

The main error I'm getting is this:

if (isset($_POST["submit"]) && isset($_FILES['upload'])) {
$image_size = getimagesize($_FILES['upload']['tmp_name']);
if ($image_size === FALSE) {
die("Unable to determine image type of uploaded file");
}

Warning: getimagesize(): Filename cannot be empty in C:\Apache24\htdocs\create.php on line 29 Unable to determine image type of uploaded file

Any help would be much appreciated!

  • 写回答

1条回答 默认 最新

  • duansha8764 2017-04-20 18:20
    关注

    You need to call at the end of php file after all the image validations

    if (move_uploaded_file($image, $any_custom_target_file_path)) {
            echo "The file has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    

    After this you can save the $any_custom_target_file_path in the database. As once the script is executed, tmp file will get deleted so we need to save this to some location.

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

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器