SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Luxembourg
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    local download instead of www.whatever.what

    Hi,
    I'm trying to setup the security of download files, instead of having the a folder in the website, I want the file on the server root (d:/webdownload/file.zip).
    Is there any way to do this (I'm using Win2k & IIS)

    Thanks

    Tzaff

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your best bet is to use php to force a download of the files. Take this example.

    Code:
    <?
    	$fileroot = 'D:\\webdownload\\\';
    	if(!file_exists($fileroot.$file)) {
    		print "Yeah right jerk";
    		exit;
    		}
    	header("204 No Content");
    	header("Content-Type: ".filetype($fileroot.$file));
    	header("Content-Disposition: attachment; filename=\"".$file."\"");
    	readfile($fileroot.$file);	
    ?>

    I named this file dl.php and stuck it in my web root. Then to allow downloading of a file not in the web root, I simply link to this file in the form of.


    dl.php?file=filetodownload.zip


    It will make sure the file exists and only in that folder, then it will force a download of the file with the proper name.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Luxembourg
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but I've got a stupid question: The file exists, I changed the 'print' to 'download will start automatically', this appears, but no download is starting... even if should... I copied your code but nada :-(

    Any suggestion(s) ?

    Tzaff

  4. #4
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Luxembourg
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but I've got a stupid question: The file exists, I changed the 'print' to 'download will start automatically', this appears, but no download is starting... even if should... I copied your code but nada :-(

    Any suggestion(s) ?

    Tzaff

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the words(Yeah right jerk) are getting printed, then the file does not exist and the prog exits. If the file exists the words(Yeah right jerk) should not be seen on the screen. I am sayingif the file DOES NOT EXIST, don't initiate the download and exit after printing an error message.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Luxembourg
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll try this again and check the spelling again and again. I'll keep you in touch

    Tzaff

  7. #7
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Luxembourg
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect, it's working fine , the admin changed the path without telling me .
    Now an other question, the last one..., when the download starts, the download screen appears with the following infos:

    You are downloading the file:
    pagename.php?id = 1 from www.mysite.lu

    But this is not very good looking. Is there a way to but the filename instead of this long info, something like:

    You are downloading the file:
    nameofthefile.zip from www.mysite.lu

    Thanks
    Tzaff


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •