Re: Downloading file from local network machine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2008-12-05 at 16:59 -0500, Bastien Koert wrote:
> On Fri, Dec 5, 2008 at 3:22 PM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>wrote:
> 
> > On Fri, 2008-12-05 at 17:32 +0000, Mayer, Jonathan wrote:
> > > Thanks Wolf :)
> > >
> > > Yup, I had considered that, although there could be up to 8 different
> > servers so that's 8 seperately mapped drives.
> > >
> > > If that's the simplest/neatest way, I'll do that, although I did wonder
> > whether there was some other clever another way around it.
> > >
> > > -----Original Message-----
> > > From: Wolf [mailto:lonewolf@xxxxxxxxx]
> > > Sent: 05 December 2008 17:29
> > > To: Mayer, Jonathan; php-general@xxxxxxxxxxxxx
> > > Subject: Re:  Downloading file from local network machine
> > >
> > > <!-- SNIP -->
> > > > I  would like to present users to our internal intranet with a link to
> > > > download a file from a folder on a different machine on our local
> > > > network (such as \\computername\folder\file)
> > > <!-- SNIP -->
> > >
> > > Map the drive to the server so that it is accessible as /folder/file on
> > the website.
> > >
> > > Voila, no more problem.
> > >
> > > HTH,
> > > Wolf
> > >
> > >
> > I don't have the code to hand right now, but I can try and post it
> > later. You were on the right track with fread() et al. Basically, set
> > the correct headers for a download (application/octet-stream I believe)
> > and print out the results of the fread(). Don't forget the binary flag
> > on fread() if you are opening binary files, and it should create a file
> > that auto-downloads. There are extra headers to set the default filename
> > of the download, but I forget these at the moment. A Google should give
> > you what you need though. This way, the file can even be delivered to
> > someone outside of your network should you wish, without you needing to
> > put the file in a web-accessible directory.
> >
> >
> > Ash
> > www.ashleysheridan.co.uk
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> function force_download($file)
> {
>     $dir      = "../log/exports/";
>     if ((isset($file))&&(file_exists($dir.$file))) {
>        header("Content-type: application/force-download");
>        header('Content-Disposition: inline; filename="' . $dir.$file . '"');
> 
>        header("Content-Transfer-Encoding: Binary");
>        header("Content-length: ".filesize($dir.$file));
>        header('Content-Type: application/octet-stream');
>        header('Content-Disposition: attachment; filename="' . $file . '"');
>        readfile("$dir$file");
>     } else {
>        echo "No file selected";
>     } //end if
> 
> }//end function
> 
> 
Two Content-type and Content-Disposition types specified here. All sorts
of wrong. It can be done with just the one of each. Get rid of the
force-download and the inline; disposition one. I just completed a
project at work that has to do this, and it works fine on IE, Fx, Opera,
and Safari. 


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux