Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.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将图像插入mysql_Php_Mysql - Fatal编程技术网

使用php将图像插入mysql

使用php将图像插入mysql,php,mysql,Php,Mysql,我正在尝试将上传的图像插入mysql,并使用会话变量中的用户id。我找到了一个在线教程,并将其更改如下: <?php require_once('../Login/includes/session_timeout_db.inc.php'); $dbuser=""; $dbname=""; $dbpass=""; $dbserver=""; $con = mysql_connect($dbserver,$dbuser,$dbpass); if (!$con){ die(

我正在尝试将上传的图像插入mysql,并使用会话变量中的用户id。我找到了一个在线教程,并将其更改如下:

<?php
require_once('../Login/includes/session_timeout_db.inc.php');
$dbuser="";
  $dbname="";
  $dbpass="";
  $dbserver="";

  $con = mysql_connect($dbserver,$dbuser,$dbpass);
  if (!$con){ die('Could not connect: ' . mysql_error()); }
  mysql_select_db($dbname, $con);

  // Make sure the user actually
    // selected and uploaded a file
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

    // Temporary file name stored on the server
    $tmpName = $_FILES['image']['tmp_name'];

    // Read the file
    $fp = fopen($tmpName, 'r');
    $data = fread($fp, filesize($tmpName));
    $data = addslashes($data);
    fclose($fp);


    // Create the query and insert
    // into our database.
    $query = "INSERT INTO images, owner_id";
    $query .= "(image) VALUES ('$data', '.$_SESSION['id'].')";
    $results = mysql_query($query, $link);

// Print results
print "Thank you, your file has been uploaded.";

}
else {
print "No image selected/uploaded";
}

// Close our MySQL Link
mysql_close($link);
?> 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” />
<title>Manage Tasks</title>
<link rel="stylesheet" type="text/css" href="../allcss/style.css" />
</head>

<body>

<?php
require('../Login/includes/header.inc.php');
?>

<div id="content">
<form enctype="multipart/form-data" action="" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>
</div>

</body>
</html>
*错误是Parse error:语法错误,意外的T_封装的_和_空白,第28行应为T_字符串或T_变量或T_NUM_字符串*

有人能帮忙吗

感谢adnvance

您的图像字段需要为类型。但不要这样做,请将文件保存在文件系统中,并将图像的目录路径保存在数据库中。

图像字段的类型必须为。但不要这样做,请将文件保存在文件系统中,并将映像的目录路径保存在数据库中。

更改:

"(image) VALUES ('$data', '.$_SESSION['id'].')";
"(image) VALUES ('$data', '".$_SESSION['id']."')";
进入:

更改:

"(image) VALUES ('$data', '.$_SESSION['id'].')";
"(image) VALUES ('$data', '".$_SESSION['id']."')";
进入: