|
Posted by Feudalac! on 10/24/05 16:01
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?
[Back to original message]
|