Re: php-general Digest 21 Dec 2000 22:27:28 -0000 Issue 416
| From: | Siim Einfeldt aka Itpunk | Date: | Thu, 28 Dec 2000 14:20:23 +0000 |
| Subject: | Re: php-general Digest 21 Dec 2000 22:27:28 -0000 Issue 416 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32078@lists.php.net to get a copy of this message | ||
This is the code that was sent to me (by Chris Lee). I think it should
work and he said it does, but I still can`t get it to display the
image. All the information is below:
// Here`S the form and the image uploader
<?php
include("connect.inc.php3");
echo "<form method=post enctype='multipart/form-data'
action='$PHP_SELF'>\n";
echo "<input type=file name=file>\n";
echo "<input type=submit>\n";
echo "</form>\n";
if (isset($file) AND $file != "none"){
$file_data = fread( fopen($file, 'r'),
filesize($file) );
$result = mysql_query("INSERT INTO temptable VALUES
('','$file_name', '$file_type', '$file_data')" );
echo mysql_error();
}
?>
This writes to the database the following (that`s an image sized
177*117):
id file_name file_type file_data
1 logoo.jpg image/pjpeg here is the image, which I didn´t manage to
send as every time I tried to paste, it pine called help...
In my opinion the file_data field is a bit too short, as the things that
I didn´t manage to paste here, was only about up to 50 characters long?
// This should show the picture
<?
include("connect.inc.php3");
$query = "SELECT * FROM temptable";
$result = mysql_db_query("bt", $query);
$r = mysql_fetch_array($result);
Header("Content-Type: {$r["file_type"]}");
echo $r["file_data"];
exit();
?>
// This is the database table
CREATE temptable(
id INT NOT NULL AUTO_INCREMENT,
file_name VARCHAR(30),
file_type VARCHAR(50),
file_data BLOB,
primary key (id));
So much trouble with such an easy thing...if you know where`s the problem,
please let me know asap.
Thanks
Siim Einfeldt 2 logoo.jpg
image/pjpeg