You are here: Re: image into mysql and out of mysql « PHP SQL « IT news, forums, messages
Re: image into mysql and out of mysql

Posted by Andreas Edin on 10/22/05 10:08

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','$for
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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация