Re: image upload/display
| From: | none | Date: | Thu, 21 Dec 2000 17:49:46 +0000 |
| Subject: | Re: image upload/display | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31449@lists.php.net to get a copy of this message | ||
<?
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 AND $file != "none")
{
$file_data = fread( fopen($file, 'r'), filesize($file) );
$result = mysql_db_query("some_db", "INSERT INTO some_table VALUES (
'$file_name', '$file_type', '$file_data' )" );
}
?>
I tested this on my box, works fine, its simple.
don't worrk about $file_name or $file_type whatever you have for a name
in your <input type=file name=chrislee> php will make for you. ie.
$chrislee_type
$chrislee_name
php is great here :)
Chris Lee
Mediawaveonline.com
In article <Pine.LNX.4.21.0012211713030.15077-100000@pshg.edu.ee>, "Siim
Einfeldt aka Itpunk" <siim_e@pshg.edu.ee> wrote:
> 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
>
>
>