
Originally Posted by
Jaan
You get that.. because I don't know why..
This is wierd.. It should display this:
Code:
die("Please select your image!");
well.. i tried another way. so in this way image should be displayed.. but it doesn't! and i really don't know why
here is the code:
form.html
Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>add pic</title>
</head>
<body>
<form action="insert.php" method="post" enctype="multipart/form-data" name="changer" >
<input name1="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpg" type="file">
<input value="Submit" type="submit">
</form>
</body>
</html>
insert.php
Code:
<?php
$username = "root";
$password = "mypassword";
$host = "localhost";
$database = "scientifc";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
// 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 article ";
$query .= "(title,text,domain_id, photo,validat) VALUES ('sdfdsdfsds','ssdafdfg',3,'$data',1)";
$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);
?>
and printimage.php
Code:
<?php
$username = "root";
$password = "mypassword";
$host = "localhost";
$database = "scientific";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
//$id = $_GET['id'];
$id = 22; // just a test id to see if it works!
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM article WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['photo'];
header('Content-type: image/jpeg');
echo $content;
}
?>
record with id 22 contains an image, in the column photo
where the f... is the problem
?
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum