上传相同ID不起作用的图片,给出路径而不是图片? [英] Upload pictures in same ID not working, giving path instead of picture?

查看:72
本文介绍了上传相同ID不起作用的图片,给出路径而不是图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图片上传到BLOB中的数据库中。每当我使用当前脚本时,它将文件路径放在BLOB而不是jpg文件中。我已经通过将blob更改为文本来测试它。



这是我每次尝试上传图片时的目的:



C:\ xamppv2 \ tmp \ php249C.tmp



我目前正在使用['tmp_name']而且我认为是这个问题的原因。我想知道我要改变什么。



这是我的代码



I'm trying to upload pictures into the database in a BLOB. Whenever I use my current script it puts the file path in the BLOB instead of the jpg file. I've tested it by changing blob to text.

This is what I currently get whenever I try to upload a picture:

C:\xamppv2\tmp\php249C.tmp

I'm currently using ['tmp_name'] and I think the is the cause of this problem. I was wondering what I have to change.

Here is my code

$tipe_file1    = $_FILES['image1']['tmp_name'];
$tipe_file2    = $_FILES['image2']['tmp_name'];
$tipe_file3    = $_FILES['image3']['tmp_name'];
$tipe_file4    = $_FILES['image4']['tmp_name'];
$prijs = $_POST['prijs'];
$naam = $_POST['fname'];
$beschrijving = $_POST['desc'];
$maat1 = $_POST['maat1'];
$maat2 = $_POST['maat2'];
$maat3 = $_POST['maat3'];
$maat4 = $_POST['maat4'];

    $aMyUploads = array();
    foreach ($_FILES as $aFile) {
        if(0 === $aFile['error']){
            $newLocation = ''.$aFile['tmp_name'];
            if(0 === $aFile['error'] && (false !== move_uploaded_file($aFile['tmp_name'], $newLocation))){
                $aMyUploads[] = $newLocation;

            } else {
                $aMyUploads[] = '';
            }
        }
    }
    $stmt = $conn->prepare("INSERT INTO `producten` (naam, beschrijving, prijs, maat1, maat2, maat3, maat4, image1, image2, image3, image4) VALUES
    (:naam, :beschrijving, :prijs, :maat1, :maat2, :maat3, :maat4, :image1, :image2, :image3, :image4)");
    $stmt->execute(array(":naam"=>$naam, ":beschrijving"=>$beschrijving, ":prijs"=>$prijs, ":maat1"=>$maat1, ":maat2"=>$maat2, ":maat3"=>$maat3, ":maat4"=>$maat4, ":image1"=>$aMyUploads[0], ":image2"=>$aMyUploads[1], ":image3"=>$aMyUploads[2], ":image4"=>$aMyUploads[3]));





我尝试了什么:



见上文,我通过将blob更改为b来测试它text。



What I have tried:

see above, I've tested it by changing blob to text.

推荐答案

tipe_file1 =
tipe_file1 =


_FILES ['image1'] ['tmp_name'];
_FILES['image1']['tmp_name'];


tipe_file2 =
tipe_file2 =


这篇关于上传相同ID不起作用的图片,给出路径而不是图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆