473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to specify the directory to download files

11
hi,

images are stored in MYSQL . What I need to do is to download the images from the database to some predefined directory in the webserver.
I am hoping that someone could help me fixing it.

Expand|Select|Wrap|Line Numbers
  1. <?PHP
  2. //download.php
  3. mysql_connect('localhost','root','') or die("Unable to connect to SQL server");
  4. @mysql_select_db('test') or die("Unable to select database");
  5. $sqlimage = "SELECT * from pix "; 
  6. $sql_imgresult = mysql_query($sqlimage) or die (mysql_error());
  7.  
  8. header("Content-type: application/force-download");
  9. header("Content-Disposition: attachment; filename=image.img");
  10. while ( $row = mysql_fetch_array ($sql_imgresult) )
  11. {
  12. $picname = $row["imgdata"];
  13. echo "$picname";
  14. }
  15. ?>
  16.  
This code downloads the image to the Desktop. But I want to download the images to the a directory where this php file reside. i.e. if this php file "download.php" is in "localhost/images" then I want to download the file to "localhost/images".

Thank You
Sep 30 '08 #1
3 1762
Markus
6,050 Expert 4TB
You can't tell the user where the file will be downloaded; PHP doesn't have those permissions, and rightly so. The user chooses where the file will be saved.
Sep 30 '08 #2
Atli
5,058 Expert 4TB
Hi.

You mean you want your images saved on the file-system of the server?

If so, try using the file_put_contents function.

But... Wouldn't it be simpler to upload the file to the file-system to begin with and just put it's location into the database?

Why do you wan't your files to be both inside the database and on the file-system?
Sep 30 '08 #3
foss
11
hi guys ,
thanks for ur reply.

I m still having problem . It would be great if you could edit this code
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?PHP
  3. mysql_connect('localhost','root','') or die("Unable to connect to SQL server");
  4. @mysql_select_db('test') or die("Unable to select database");
  5. $sqlimage = "SELECT * from pix "; 
  6. $sql_imgresult = mysql_query($sqlimage) or die (mysql_error());
  7.  
  8.  $upload_url = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']) . '/';
  9.  $file_path =  $upload_url."imageTemp/ab1.img";
  10.  
  11. header("Content-type: application/force-download");
  12. header("Content-Disposition: attachment; filename=ab1.img");
  13.  
  14. while ( $row = mysql_fetch_array ($sql_imgresult) )
  15. {
  16. $picname = $row["imgdata"]; //picname is the name of the field in the images table
  17. echo "$picname";
  18.  file_put_contents  ( $file_path  , $picname);
  19. }
  20.  
  21. ?>
  22.  
I personally appreciate the idea of storing the file path in the database and storing the images(files) in the file system.That is easy to do and a number of tried and true examples are available in the web.
But here i have to store them in Mysql it would be easier for dealing with other things like synchronization and security
Oct 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jane Doe | last post by:
Hi, I need to add a download function in a VB program, but since a file can be located anywhere in our /download section on the web, I was thinking of putting a PHP script there that would take...
2
by: spike | last post by:
I tried to upload a .htaccess-file to the directory that i wanted to protect. This is what I wrote in it: ------------------------------------------------ <Limit GET> order deny,allow deny from...
0
by: CodeMotion | last post by:
I have access to an internet directory and files will be placed in this directory periodically. I am writing a service to poll that directory and download the files for processing. I have figured...
5
by: Verane | last post by:
Hi, I have read the thread named "Could not copy temporary files to the output directory" on this newsgroup. And I have the same symptoms on my machine. But I didn't find any solution suitable for...
2
by: OpticTygre | last post by:
I have a directory of 27 files. The files end in either 1.txt, 2.txt, 3.txt, or 4.txt. If I say: For Each filename As String In...
23
by: **Developer** | last post by:
Is there an easy way to copies all files in a directory into another directory? What about coping subdirectories too? Thanks in advance for any info
2
by: Danny Boy | last post by:
Hi, "Snif" is an excellent little script to index files and directories. It's just one single file, and the advantage is that you merely drop it into the directory you want to index, point a...
2
by: Paul | last post by:
I need to copy files from an ftp directory to a web-accessible directory and then delete the files in the ftp directory. (I am doing it this way because web-based form upload can not exceed 2MB...
6
by: Scubadude | last post by:
Hi, I'm new to perl and have run into some roadblocks while trying to run tutorials. I have installed Apache v2.2.3 I have installed ActivePerl v6.6.1.638 I have installed php v5.2.0 I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.