|
Posted by rich on 10/24/05 21:23
In article <djiluo$6tr$1@ss405.t-com.hr>, Feudalac! says...
>
>Andreas Edin wrote:
>
>>
>> It's pretty easy upload and download images or other files
>> to and from a MySql server.
>>
>> Here is an example how to upload it:
>> <?php
>> require('connect/open_connect.php');
>>
>> $form_description = $_POST['form_description'];
>> $form_type_upload = $_POST['type_upload'];
>> $data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'],
>> "rb"), filesize($_FILES['form_data']['tmp_name'])));
>> $form_data_name = $_FILES['form_data']['name'];
>> $form_data_size = $_FILES['form_data']['size'];
>> $form_data_type = $_FILES['form_data']['type'];
>> }
>>
>> $result=MYSQL_QUERY("INSERT INTO binary_data (categori,
>> description,bin_data,filename,filesize,filetype) ".
>> "VALUES
>> ('$form_type_upload','$form_description','$data','$form_data_name','$f
>> or m_data_size','$form_data_type')");
>>
>> require('connect/close_connect.php');
>> ?>
>>
>> Here is an example how to download for viewing or download:
>> <?php
>>
>> if($_GET['id']) {
>> require('connect/open_connect.php');
>>
>> $query = "select description, bin_data, filename, filesize,
>> filetype from binary_data where id=".$_GET['id'];
>> $result = @MYSQL_QUERY($query);
>>
>> $data = @MYSQL_RESULT($result,0,"bin_data");
>> $type = @MYSQL_RESULT($result,0,"filetype");
>> $size = @MYSQL_RESULT($result,0,"filesize");
>> $name = @MYSQL_RESULT($result,0,"filename");
>> $desc = @MYSQL_RESULT($result,0,"description");
>>
>> require('connect/close_connect.php');
>>
>> header("Content-type: $type");
>> header("Content-length: $size");
>> header("Content-Disposition: attachment; filename=$name");
>> header("Content-Description: $desc");
>> echo $data;
>>
>> };
>> ?>
>>
>> Internet explorer will try to open det file/image, and if it can't
>> open it with a program it will send you a download prompt insteed.
>>
>> Good Lucky! If you want more detailed description just say it.
>> Best regards Andreas Edin, Sweden
>
>but what if i don't want to download them? i want to show them in a
>html page?
>
If you didn't want to store and retrieve the images through MySQL, you can store
the path information instead. That way you only have to use and maintain a
simple string of text.
Since you want to display images in your HTML, they would usually be stored in
your web space. You can use SQL to build some type of query (e.g. sort by date,
name, etc) and dynamically print the results in your HTML using the file name
and/or path information.
Rich
--
Newsguy -- http://newsguy.com
Navigation:
[Reply to this message]
|