Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试将图像插入blob字段_Php_Mysql_Blob - Fatal编程技术网

Php 尝试将图像插入blob字段

Php 尝试将图像插入blob字段,php,mysql,blob,Php,Mysql,Blob,我正在尝试使用php通过web表单将一个小图像插入mysql数据库。但它不起作用。怎么了 表格: 很可能是addslashes()。使用一个或更好的方法。这里有一个简单的例子一直对我很有用: # create table blobs( id int(11) NOT NULL auto_increment, myblob longblob, PRIMARY KEY (id)); $host = "localhost"; $username = "blobtest"; $password

我正在尝试使用php通过web表单将一个小图像插入mysql数据库。但它不起作用。怎么了

表格:


很可能是
addslashes()
。使用一个或更好的方法。

这里有一个简单的例子一直对我很有用:

# create table blobs( id int(11) NOT NULL auto_increment, myblob longblob, PRIMARY KEY (id));


$host     = "localhost";
$username = "blobtest";
$password = "blobtest";
$database = "blobtest";

$link_id = @mysql_connect($host, $username, $password);
@mysql_select_db($database);

$blob = file_get_contents('stripe.png');
$bdata = addslashes($blob);

$qry = "INSERT INTO blobs VALUES(NULL, '$bdata')";
mysql_query($qry);

我有点想问你你的电脑是否开机了:)你收到什么错误信息了吗?是的,电脑开机了……哈哈。没有错误信息,只是没有上传文件。什么都没有,你为什么问?他在编辑答案时天真地吹口哨
$fileName = $_FILES['cover']['name'];
 $tmpName = $_FILES['cover']['tmp_name'];
 $fileSize = $_FILES['cover']['size'];
 $fileType = $_FILES['cover']['type'];

 $fp = fopen($tmpName, 'r');
 $content = fread($fp, filesize($tmpName));
 $content = addslashes($content);
 fclose($fp);

 if(!get_magic_quotes_gpc())
 {
$fileName = addslashes($fileName);
 }

$query = "INSERT INTO games set name='".$fileName."', size='".$fileSize."', type='".$fileType."', content='".$content."'";
 mysql_query($query) ;
# create table blobs( id int(11) NOT NULL auto_increment, myblob longblob, PRIMARY KEY (id));


$host     = "localhost";
$username = "blobtest";
$password = "blobtest";
$database = "blobtest";

$link_id = @mysql_connect($host, $username, $password);
@mysql_select_db($database);

$blob = file_get_contents('stripe.png');
$bdata = addslashes($blob);

$qry = "INSERT INTO blobs VALUES(NULL, '$bdata')";
mysql_query($qry);