image upload/display
| From: | Siim Einfeldt aka Itpunk | Date: | Thu, 21 Dec 2000 15:13:26 +0000 |
| Subject: | image upload/display | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31433@lists.php.net to get a copy of this message | ||
Hey folks,
I`m having hard time on getting the picture upload/displaying to
work. Actually it seems to write all the needed things to the database,
but it doesn´t show the picture. If you would, check the following(all the
files that work with the upload) and see if you find any problems with it.
<?php
/* This is the most important part of the upload form *//*form.php3*/
echo ('<INPUT TYPE="file" NAME="form_data">');
?>
<?php
/* This is the actual uploader *//*form_upload.php3*/
include("connection.php3");
$pildityyp="$form_data_type";
$pildistaatus="fill the fields. ";
if (eregi("image",$pildityyp)) {
$pildistaatus="OK";
} Else {
$pildistaatus="You can upload only pictures, but
you tried to upload '$pildityyp'.";
}
if($img1=="none") {
$pildistaatus="The file field was left empty.";
}
echo "Picture status is $pildistaatus";
if ($pildistaatus=="OK") {
$data = addslashes(fread(fopen($form_data, "r"),
filesize($form_data)));
mysql_query("INSERT INTO
pildid (tyyp,subid,pic,picname,picnr,content_type) VALUES ('".$tyyp."',
'".$subid."', '".$data."',
'".$picname."',
'".$picnr."','".$form_data_type."')");
if(mysql_error()==""){
$mes="The picture has been added!";
}else{
$mes="Couldn`t change the picture";
}
echo
"<SCRIPT>location.href='admin.php3?mes=$mes'</SCRIPT>";
die;
}
}
?>
<?php
/* THIS GETS THE DATA FOR DISPLAYING THE PICTURE *//*showpic.php */
include ("connection.php3");
$query = "select pic,content_type from pildid WHERE id='31'";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0, "pic");
$type = @MYSQL_RESULT($result,0, "content_type");
Header("Content-type: $type");
echo $data;
?>
<!-- This is the file that should display the image//-->
<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY>
<?php
echo('<IMG SRC="showpic.php">');
?>
</BODY>
</HTML>
Thanks in advance,
Siim Einfeldt