By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 1,608 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

download file

P: n/a
Ken
How do I download files from the internet server to my computer?

How do I tell the script the correct hard drive folder on my computer to
copy the files to?

After connecting to the internet server, I am trying:

$_SESSION['archive_dir_read'] = "/uploaddir/"; // directory on server
$_SESSION['archive_dir_store'] = "c:/_picture_file/"; // directory on
computer

copy($_SESSION['archive_dir_read'].$_SESSION['picture1'],
$_SESSION['archive_dir_store'].$_SESSION['picture1'])

$_SESSION['picture1'] is the file name

How do I address my computer from the internet?

ftp://c:/_picture_file/

or http://c:/_picture_file/

http://ip address/c:/_picture_file/

Thanks for the help.

Ken
Jul 17 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
*** Ken wrote/escribi (Wed, 18 Aug 2004 08:11:16 GMT):
How do I address my computer from the internet?


Luckily, that's impossible! Let your web browser download it. Point browser
to http://domain.com/folder/file.extension and then use the "Save as"
option.
--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Jul 17 '05 #2

P: n/a
Ken
> > How do I address my computer from the internet?
I can see why that is not done!!

Can I place the download script on my computer and pull the files down to my
hard drive?

Rather than push them down from the internet server.

I have a number of files; the number will vary and is controlled by the
webpage I am writing. The viewer uploads the files to a server directory.
I need to find an PHP script to transfer the files to my computer. I would
like PHP to automatically download the proper file.

There must be way of taking the files off the internet server and moving
them to my hard drive.

How do I do that?
Can I configure the copy command to do that?

Thanks for the help.

Ken

$_SESSION['archive_dir_read'] = "/uploaddir/"; // directory on
server
$_SESSION['archive_dir_store'] = "c:/_picture_file/"; // directory on
computer

copy($_SESSION['archive_dir_read'].$_SESSION['picture1'],
$_SESSION['archive_dir_store'].$_SESSION['picture1'])

$_SESSION['picture1'] is the file name
"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:1h****************************@40tude.net...
*** Ken wrote/escribi (Wed, 18 Aug 2004 08:11:16 GMT):
How do I address my computer from the internet?
Luckily, that's impossible! Let your web browser download it. Point

browser to http://domain.com/folder/file.extension and then use the "Save as"
option.
--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--

Jul 17 '05 #3

P: n/a
*** Ken wrote/escribi (Wed, 18 Aug 2004 09:16:46 GMT):
Can I place the download script on my computer and pull the files down to my
hard drive?


Sure, but of course you need the adequate environment (a web server
accesible from outside and a PHP interpreter). It's probably easier to just
use a download tool like GetRight or wget and program the download. Some of
them (esp. wget) are very flexible.
--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Jul 17 '05 #4

P: n/a
Ken
I have apache server on my computer also php.

Do I have to change the configuration on the server to access the outside?
I use the server to develop the php and MySql scripts.

Can you suggest a script a script?

I really appreciate the help!

Ken

"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:aa****************************@40tude.net...
*** Ken wrote/escribi (Wed, 18 Aug 2004 09:16:46 GMT):
Can I place the download script on my computer and pull the files down to my hard drive?
Sure, but of course you need the adequate environment (a web server
accesible from outside and a PHP interpreter). It's probably easier to

just use a download tool like GetRight or wget and program the download. Some of them (esp. wget) are very flexible.
--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--

Jul 17 '05 #5

P: n/a
*** Ken wrote/escribi (Wed, 18 Aug 2004 16:58:31 GMT):
Do I have to change the configuration on the server to access the outside?
I use the server to develop the php and MySql scripts.


It really depends on many factors: Apache config, firewalls, routers...
Apache must be listening your PC's external IP (not only 127.0.0.1),
firewall must allow external access to port 80 and routers must have NAT
configured to send traffic to your computer.

--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Jul 17 '05 #6

P: n/a
Ken
"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:14*****************************@40tude.net...
*** Ken wrote/escribi (Wed, 18 Aug 2004 16:58:31 GMT):
Do I have to change the configuration on the server to access the outside? I use the server to develop the php and MySql scripts.


It really depends on many factors: Apache config, firewalls, routers...
Apache must be listening your PC's external IP (not only 127.0.0.1),
firewall must allow external access to port 80 and routers must have NAT
configured to send traffic to your computer.

--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--


I set up PHP as follows: But the file save dialog box does not open in
Internet Explorer version 6.0.2800.1106.

$type = image/pjpeg
$size = 3548
$pict = the-picture-name.jpg

header("Content-type: application/$type");
header("Content-disposition: attachment; filename=$pict");
header("Content-length: $length");
readfile('$pict');

What am I doing wrong?

Thanks!

Ken
Jul 17 '05 #7

P: n/a
Ken
$file = directory/WI-1117-01.gif
header( "Content-Description: File Transfer" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

//header( "Content-Type: application/force-download" );
header( "Content-Type: image/gif" );
header( "Content-Disposition: attachment; filename=test.gif" );
header( "Content-length: ".filesize($file));
header( "Content-Transfer-Encoding: binary" );

$testt = readfile($file);
echo "<br><br>testt = ".$testt;

echo "<br><br>Completed";

-------------------------------------------------------
I have made some changes.

I can now display the ASCII code for the image on my screen. The image is
the visa.gif

WI-1117-01.gif , image/gif , 518
GIF89a8$33f3f3ff3fTffTfTTTTT3fTTTTT 3TffT,8$@
"ZdizhSpܲmmB9^,T`(@AZGtJ=2Oլz xL~z=:OC`%:
( X-wr:URSC#X "u 7"OI'?S\eoz^nZ54lj*[hU="- <
5-Y?P<?T8"--:MfPG 5CBE, T>Y
..VHJfs`Z"?'BoxJ!?jOJs ' <;$uuoB' "
",<-s<'T,.Z@fd~?5hB
*QG\?,IX@"Y????.?]#oqrO893``
"̍HTS~\̹K/S&;

testt = 518 // this is the result of readfile statement. The file size.
So I am now in contact with the correct file, file size, and have downloaded
the file as ASCII to the screen but did not saved it as a file (test.gif) on
my hard drive.

Completed
-------------------------------------------------

I read there is a problem with IE 6.0 I could not find a fix for it.

Do you know the file name or number for the fix? Q??? K???
Is the above script correct for readfile() and the headers?

Ken
Jul 17 '05 #8

P: n/a
*** Ken wrote/escribi (Mon, 23 Aug 2004 21:44:19 -0500):
readfile('$pict');


That way you're reading a file called $pict. Variables are not parsed
within single quotes. Try:

readfile($pict);
--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Jul 17 '05 #9

P: n/a
*** Ken wrote/escribi (Tue, 24 Aug 2004 01:37:28 -0500):
$testt = readfile($file);
echo "<br><br>testt = ".$testt;

echo "<br><br>Completed";


The echo's are fine for debugging but, of course, if you use them in the
final script your file will be messed.

--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Jul 17 '05 #10

P: n/a
Ken
header( "Content-Disposition: attachment;
filename=".$_SESSION['pictures'.$i]);
header( "Content-Type:".$_SESSION['pictures'.$i.'_type']);
header( "Content-length: ".$_SESSION['pictures'.$i.'_size']);
header( "Content-Transfer-Encoding: binary" );
readfile($_SESSION['archive_dir_read'].$_SESSION['pictures'.$i]);

I finally was able to save a file from the internet server to my hard drive
thanks to all the help I received from the newsgroup.

For the next person to ask the question about downloading files, a few
pointers.
We know this but do not remember it.

The headers must be before any writing to the display, including html and
echo.
So basically, add a separate page for the headers.

I do have four other questions.
1. How do I define the hard drive directory for the files in the headers?
I added it to the filename, then the file name became the page name,
i.e., file.gif became download.gif download.php is the page file name.
header( "Content-Disposition: attachment;
filename=c:/temp/".$_SESSION['pictures'.$i]); The manual says the directory
name cannot be specified. Is that still true? Any work arounds?

2. Can I download multiple files at one time? Can you suggest a script for
handling multiple files?

3. Is there a way to download the files without going through the file
download box? Open the page and the files download to the specified
directory.

4. Do I need any other headers?

Thanks!!

Ken
Jul 17 '05 #11

P: n/a
*** Ken wrote/escribi (Wed, 25 Aug 2004 04:49:18 -0500):
1. How do I define the hard drive directory for the files in the headers?
I'm pretty sure you cannot. Maybe that's a good idea: if you aren't careful
when browsing the web a malicious site could overwrite any important file
in your hard drive. Just think of all the times you've got a dialog when
about to type "enter" in your text editor ;-)
2. Can I download multiple files at one time? Can you suggest a script for
handling multiple files?
Short answer: no. HTTP connections are not persistent. Once the file is
served, the connection is closed. Even if the connection is keep-alive
type, I guess you need a browser request to serve another fiel. (Not sure
about pipelining though).

Workaround: use JavaScript to open pop-up windows and make it work through
usual pop-up blockers--i.e., make the window.open get tryggered by an user
event.
3. Is there a way to download the files without going through the file
download box? Open the page and the files download to the specified
directory.
See first point. There *are* ways, but you probably need to write an
ActiveX control or signed Java applet.
4. Do I need any other headers?


I don't think so.

--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Jul 17 '05 #12

P: n/a
Ken
Thanks for the help.

Ken

"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:17*****************************@40tude.net...
*** Ken wrote/escribi (Wed, 25 Aug 2004 04:49:18 -0500):
1. How do I define the hard drive directory for the files in the headers?

I'm pretty sure you cannot. Maybe that's a good idea: if you aren't careful when browsing the web a malicious site could overwrite any important file
in your hard drive. Just think of all the times you've got a dialog when
about to type "enter" in your text editor ;-)
2. Can I download multiple files at one time? Can you suggest a script
for handling multiple files?


Short answer: no. HTTP connections are not persistent. Once the file is
served, the connection is closed. Even if the connection is keep-alive
type, I guess you need a browser request to serve another fiel. (Not sure
about pipelining though).

Workaround: use JavaScript to open pop-up windows and make it work through
usual pop-up blockers--i.e., make the window.open get tryggered by an

user event.
3. Is there a way to download the files without going through the file
download box? Open the page and the files download to the specified
directory.


See first point. There *are* ways, but you probably need to write an
ActiveX control or signed Java applet.
4. Do I need any other headers?


I don't think so.

--
-- lvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--

Jul 17 '05 #13

P: n/a
Alvaro G Vicario wrote:
*** Ken wrote/escribi (Wed, 25 Aug 2004 04:49:18 -0500):
2. Can I download multiple files at one time? Can you suggest a
script for handling multiple files?


Short answer: no. HTTP connections are not persistent. Once the file
is served, the connection is closed. Even if the connection is
keep-alive type, I guess you need a browser request to serve another
fiel. (Not sure about pipelining though).

Workaround: use JavaScript to open pop-up windows and make it work
through usual pop-up blockers--i.e., make the window.open get
tryggered by an user event.


IE sucks in this aspect. If you expect that the users would use Mozilla
or some other browser that can handle MIME multipart content, it should
work with the following script:
- - - - - - - - -
<?
define(BOUNDARY, "thisistheboundary");
header("Content-type: multipart/mixed; boundary=\"". BOUNDARY ."\"");
header("MIME-version: 1.0");

$file1="pic1.jpg";
$file2="pic2.jpg";

$fh = fopen($file1, "r");
$content1 = fread($fh, filesize($file1));
fclose($fh);

$fh = fopen($file2, "r");
$content2 = fread($fh, filesize($file2));
fclose($fh);

echo "--". BOUNDARY ."\r\n";
echo "Content-type: image/jpeg\r\n";
echo "Content-description: pic1.jpg\r\n";
echo "Content-disposition: attachment; filename=\"pic1.jpg\"\r\n\r\n";
echo $content1;

echo "\r\n\r\n--". BOUNDARY ."\r\n";
echo "Content-type: image/jpeg\r\n";
echo "Content-description: pic2.jpg\r\n";
echo "Content-disposition: attachment; filename=\"pic2.jpg\"\r\n\r\n";
echo $content2;

echo "\r\n\r\n--". BOUNDARY ."\r\n";
echo "Content-type: text/html\r\n\r\n";

echo "<html>
<head>
<title>dl finished</title>
<body>
<h2>Finished downloading</h2>
</body>
</html>\r\n";
echo "\r\n--". BOUNDARY ."--\r\n";
?>
- - - - - - - - -

At least it worked when I tested with Mozilla Firefox, but I couldn't
figure out how IE would handle the multiparts properly.

- Aki
Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.