DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

image download

By: | 18 Feb 2009 2:55 am

Dear Sirs

i have number of jpg images. I want to store these images in mysql,retreive on webpage, then to download the particular image whom visitor click.

plz help me i will be very thankfull

Comments


here is your solution friend
http://www.php-mysql-tutorial.com/php-mysql-upload.php

 

 

By: | 18 Feb 2009


Never store binary data in a database if you can avoid it.
There are a lot of reasons. The most important ones:
Space requirement (mysql has to encode)
Performance (a database needs to query, decode and send data)
Backup Speed (mysqldump into csv and binary data do not work well)

Just store the images outside the document root and use a php file to
passthru. Doing so is more performant and can be secured.

By: | 18 Feb 2009

Dear sir..
this is what i am working out....

==============================================================
<table border="1" bordercolor="#0000FF" width="21%" cellpadding="5"

cellspacing="5">

<?

$i = 0;
$q = mysql_query ("Select * from stuff where cat_id = `1` ");
while($r = mysql_fetch_array($q))
{
if ($i==2)
{
$i=0;
}
$i+=1;

?>
<tr>
<td width="41%"><img src="images/<? echo $r["image_path"]?>" /></td>
</tr>

<tr>
<td width="20%"><?php echo $r["image_name"]?></td>

<td><a href="images/?add_id=<? echo $r["prod_id"]?>">Download</a></td>
</tr>
<?
}
?>

</table>
============================================================

one thing that i have just stored the image name in mysql and store the all
image in a saperate folder name images..as shown in the code above.. i want that
when i click the download button the download box open and the image start to
download.

By: | 18 Feb 2009

Hello,

We type below previous posts in this group.

You didn`t mention what file types that the image files are. ie - .jpeg . jpg
.png .gif .bmp

You need another php file to force the download. See the headers() function on
php.net

The above code will need to be changed to -

<td width="41%"><img src="images/download.php?image=<? echo $r["image_path"]?>"
/></td>

The important part is to make sure that the only files that the download script
will download are
image files from the correct location.

I need to know what file types are acceptable to write the validation for you.

Thanks,

By: | 18 Feb 2009

Hello,

We type below previous posts in this group.

You didn`t mention what file types that the image files are. ie - .jpeg . jpg
.png .gif .bmp

You need another php file to force the download. See the headers() function on
php.net

The above code will need to be changed to -

<td width="41%"><img src="images/download.php?image=<? echo $r["image_path"]?>"
/></td>

The important part is to make sure that the only files that the download script
will download are
image files from the correct location.

I need to know what file types are acceptable to write the validation for you.

Thanks.
------------------------------------

Correction -

<td width="41%">

<a href="images/download.php?image=<?php echo($r[`image_path`]); ?>">
<img src="images/<? echo $r["image_path"]?>" />
</a>
</td>

Does the image path have any spaces?

By: | 18 Feb 2009

---------------------------------------

<td width="41%">
<a href="download.php?img=<?php echo($r[`image_path`]); ?>">
<img src="images/<? echo $r["image_path"]?>" />

</a>
</td>

download.php ...
<?php

if(isset($_GET[`img`]))
{
if(download_img($_GET[`img`]))
{
die();
}
}

function download_img($image_filename)
{
$path_parts = pathinfo($image_filename);
$dirname = $path_parts[`dirname`];
if(($dirname != "") && ($dirname != ".")) return FALSE;
// the image must have no path info aprt from above
$ext = $path_parts[`extension`];
$permitted = "jpg jpeg png gif bmp";
$permitted = explode(" ", $permitted);
foreach($permitted as $this_ext)
{
if($ext = $this_ext)
{
return output_img($path_parts[`basename`]);
}
}
return FALSE;
}

function output_img($filename)
{
if(!file_exists("images/" . $filename))
// hard code the path information so that this
// script can`t be used to access other folders
{
//echo("[" . $filename . "] Does not exist<br>n");
return FALSE;
}
if(!is_readable("images/" . $filename))
{
//echo("[" . $filename . "] Is not readable<br>n");
return FALSE;
}
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($filename));
header(`Content-Disposition: attachment; filename="` . $filename . `"`);
header("Content-Transfer-Encoding: binaryn");
readfile("images/" . $filename);
return TRUE;
}

?>

<b>Hacking not permitted</b> etc....

Also note that this script can be placed ate the beging if the script that
generated the image
selection page so that the pinter can be ...
<td width="41%">
<a href="<?php echo($_SERVER[`PHP_SELF`]); ?>?img=<?php echo($r[`image_path`]);
?>">
<img src="images/<? echo $r["image_path"]?>" />

</a>
</td>

By: | 18 Feb 2009

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move