简体   繁体   English

如何将图像插入 mysql 数据库?

[英]How to insert image into mysql database?

i am trying to get the uploaded image inserted into mysql database but i get this error msg.我正在尝试将上传的图像插入 mysql 数据库,但我收到此错误消息。 help please.请帮忙。 here is the error i get这是我得到的错误

Array
(
    [name] => Zonsondergang.jpg
    [type] => image/jpeg
    [tmp_name] => /tmp/phpU9qSru
    [error] => 0
    [size] => 71189
)

data/Zonsondergang.jpg test file successfully loaded data/Zonsondergang.jpg 测试文件加载成功

Warning: file_get_contents(/tmp/phpU9qSru) [function.file-get-contents]: failed to open stream: No such file or directory in /home/meer/domains/skyup.nl/public_html/upload_Class/upload.php on line 68 Error!警告:file_get_contents(/tmp/phpU9qSru) [function.file-get-contents]:无法打开 stream:/home/meer/domains/skyup.nl/public_html/upload_Class/upload.ZE1BFD762321E409CEE4AC0B6E841 行中没有这样的文件或目录68 错误! Failed to insert the file1插入文件失败1

here is my code for uploading image and inserting the image into database这是我上传图像并将图像插入数据库的代码

include('../inc/con_inc.php');

// Defining Class
$uploaded = new upload;

// Set Max Size
$uploaded->set_max_size(350000);

// Set Directory
$uploaded->set_directory("data");

// Set Temp Name 
$uploaded->set_tmp_name($_FILES['file']['tmp_name']);

// Set file size, 
$_FILES['file']['size'] is automaticly get the size
$uploaded->set_file_size($_FILES['file']['size']);


// Set File Type,
 $_FILES['file']['type'] 
$uploaded->set_file_type($_FILES['file']['type']);

// Set File Name, 
$uploaded->set_file_name($_FILES['file']['name']);


// Start Copy Process
$uploaded->start_copy();


$name=($_FILES['file']['name']);
$data=(file_get_contents($_FILES['file']['tmp_name']));


$query="INSERT INTO download(name,data) VALUES('$name','$data')";
if ($result){
 echo 'Success! Your file was successfully added!';
 }else{
 echo 'Error! Failed to insert the file' ;
 $result=mysql_query($query) or die ('query fout');

 }

here is the stracture of table:这是表的结构:

create table download (
    id int primary key not null 
auto_increment,
    name varchar(60),
    data longblob)
$data=(file_get_contents($_FILES['file']['tmp_name']));

you can't do that since you've just uploaded your file with the upload class.您不能这样做,因为您刚刚使用upload class 上传了文件。
you should have a method or a variable from witch you get the actual uploaded file, something like: $uploaded->get_file()你应该有一个方法或一个变量,你可以得到实际上传的文件,比如: $uploaded->get_file()
you should get file content from there (the file uploaded in your 'data' folder)您应该从那里获取文件内容(上传到您的“数据”文件夹中的文件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM