First, you HAVE TO ensure that you have set the following line in your "php3.ini" file:
upload_tmp_dir=./ ;some comments happen to be here
(it is often not assigned like this:
upload_tmp_dir= ;the comments)
Second step is to run mysql client and:
mysql> create database test;
mysql> use test;
mysql> create table images(
id int auto_increment,
the_image longblob not null,
primary key(id)
);
Third step is to create file "test.php" in your htdocs directory and copy into the file the following:
<?
mysql_connect("localhost","httpd","");
mysql_select_db("test");
if(!isset($command)){
header("Content-type: text/html");
echo "<body>
browse for a file to upload
<form method=\"post\" action=\"?command=add\" enctype=\"multipart/form-data\">
<input type=\"file\" name=\"the_file\" accept=\"image/jpeg\">
<input type=\"submit\">
</form><hr>
choose db_image_index to view
<form method=\"post\" action=\"?command=show\" target=\"_self\">
<select name=\"id\">\n";
$list=mysql_query("select id from images where the_image is not null");
while($index=mysql_fetch_row($list))
echo " <option>$index[0]\n";
echo " </select>\n <input type=\"submit\">\n </form>\n</body>";
}else{
if($command=="add"){
header("Content-type: text/html");
echo "file \"$the_file...\" added. <a href=\"test.php\" target=\"_self\">get back</a>.";
$file=addslashes(fread(fopen($the_file,"r"),filesize($the_file)));
mysql_query("insert into images values(null,'$file')");
}elseif($command=="show"){
header("Content-type: image/jpeg");
$data=mysql_result(mysql_query("select the_image from images where id=$id"),0,"the_image");
echo $data;
}
}
mysql_close();
?>
- similar stuff you might found before - as did - but there always had been next questions and complaints...