Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 20
  1. #1
    Senior Member joncom11's Avatar
    Join Date
    Oct 2003
    Posts
    284
    Member #
    3532
    Help! I have heard something about "headers" and how you can make it seem that a file is being downloaded from "examplesite.com" when really it's being taken off of "theothersite.com".

    Apparently this script does it:

    http://home.support.nl/~lemmen/anti-...leech.php3.txt

    But I have not been able to get that script to work. Yes my host supports php.. I have no clue why it won't work.

    For my site I have a load of files on a dedicated server, but I don't want people just see my server's IP when downloading, I want it to look like it's coming off of my domain address..

    Can someone please help me out?
    Pixel Fuse - Signature webpage, just a spashpage.
    Flash Frogger - Frogger remake, animated/coded in Flash (incomplete/discontinued)
    Daase Art Studio - Homepage of David Daase, a Canadian landscape artist - image gallery/showcase.
    More links if I think of some...

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    If I understand you correctly, you want to show your domain adress in the download dialog box that pop's up, instead of showing the path to the file (or URL to file, if the file is beeing downloaded from another server.)

    You need to make a page that contains a presentation of the files (filename or other descriptive info) you make available for download.
    Each of these links (or request buttons) need to be encapsulated in form tags. You make hidden input fields, containing the real filename. The form action is set to a script page, in my example "download_code.php".
    That scripts executes the real download, and will never be visible to the public. In the pop up dialog box that asks where you want to store the file, it will only state the name of the file, type of file and where from which domain the script is running.
    I.e. not where the files are coming from, but just the domain name of the server where the "download_code.php" is running.

    I use this on my server to download images, but you can alter the script to reflect any type of file. You can also replace the file type definition with a variable that pick up the file type from elsewhere if you have a lot of different filetypes you want to share.

    This is a description of the form encapsulation from the links page:
    (I use a thumbnail image as a "request" button, you can of course use a normal button)
    Code:
     <form name="form1" method="post" action="../download/download_code.php">
              <input type="hidden" name="image" value="some_pic.jpg">
              <td ><input type='image' 
    src='../images/thumbnails/some_pic.jpg' name='submit'></td></form>
    This is the download_code.php script.
    PHP Code:
    <?php
    /* If the source is on an other server, you just replace the
    argument to fopen to "http://www.someserver.com/directory/subdirectory") */
    $fp fopen("../images/download/$_POST['image'] ","r");

    //Set the max byte size
    $buff fread($fp,1500000);

    /*The "image/jpeg" can be replaced by a variable 
    containing file type as explained above. */
    Header("Content-Type: image/jpg");
    Header"Content-Disposition: attachment; filename=$_POST['image']");

    //Start output
    echo $buff;
    ?>
    S. Rosland

  4. #3
    Senior Member joncom11's Avatar
    Join Date
    Oct 2003
    Posts
    284
    Member #
    3532
    couple questions...
    --------------------------------------

    so if i want the maximum file size to big a gig.... i do this?

    //Set the max byte size
    $buff = fread($fp,1000000000);



    and if i want to have .zip as the files to download i do this?

    /*The "image/jpeg" can be replaced by a variable
    containing file type as explained above. */
    Header("Content-Type: file/zip");
    Header( "Content-Disposition: attachment; filename=$_POST['image']");



    and for telling it that the files are located on a different server i do this?

    /* If the source is on an other server, you just replace the
    argument to fopen to "http://www.someserver.com/directory/subdirectory") */
    $fp = fopen("http://mydifferentserver.com/myfiles/$_POST['image'] ","r");



    at the moment i get this error when i try to download something:

    [/b]Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/virtual/site127/fst/var/www/html/dltesting/download_code.php on line 4[/b]

    line 4 is:

    $fp = fopen("http://myurlgoeshere/myfiles/$_POST['image'] ","r");
    Pixel Fuse - Signature webpage, just a spashpage.
    Flash Frogger - Frogger remake, animated/coded in Flash (incomplete/discontinued)
    Daase Art Studio - Homepage of David Daase, a Canadian landscape artist - image gallery/showcase.
    More links if I think of some...

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    I haven't tried using 1GB as a filesize limit. I'm not sure if you need to split it up if it gets that big. I'll check on that.

    I'm not sure why you get the error. I tried the code first, and replacing the directory with an absolute URL worked fine for me. Have you made sure the"$_POST['variable']" actually contains a value? Do you have chmod read access to the file in question? Do you need to log in to gain access to that file? If so, the script in its present form won't work.

    When it comes to file type definition (zip.exe.xls whatever) I will try to see if I can find out what the correct MIME type is. I've tried it with jpeg, gif, png, and txt. That works fine. However, all file types are "downloadable" .

    Maybe some more skillfull people here can give you an answer before I figure it out.

    BTW, you said you didn't get the original code to work, but you didn't specify what errors it gave you.
    S. Rosland

  6. #5
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Here are a list of MIME types for different file types:

    "ez" => "application/andrew-inset",
    "hqx" => "application/mac-binhex40",
    "cpt" => "application/mac-compactpro",
    "doc" => "application/msword",
    "bin" => "application/octet-stream",
    "dms" => "application/octet-stream",
    "lha" => "application/octet-stream",
    "lzh" => "application/octet-stream",
    "exe" => "application/octet-stream",
    "class" => "application/octet-stream",
    "so" => "application/octet-stream",
    "dll" => "application/octet-stream",
    "oda" => "application/oda",
    "pdf" => "application/pdf",
    "ai" => "application/postscript",
    "eps" => "application/postscript",
    "ps" => "application/postscript",
    "smi" => "application/smil",
    "smil" => "application/smil",
    "wbxml" => "application/vnd.wap.wbxml",
    "wmlc" => "application/vnd.wap.wmlc",
    "wmlsc" => "application/vnd.wap.wmlscriptc",
    "bcpio" => "application/x-bcpio",
    "vcd" => "application/x-cdlink",
    "pgn" => "application/x-chess-pgn",
    "cpio" => "application/x-cpio",
    "csh" => "application/x-csh",
    "dcr" => "application/x-director",
    "dir" => "application/x-director",
    "dxr" => "application/x-director",
    "dvi" => "application/x-dvi",
    "spl" => "application/x-futuresplash",
    "gtar" => "application/x-gtar",
    "hdf" => "application/x-hdf",
    "js" => "application/x-javascript",
    "skp" => "application/x-koan",
    "skd" => "application/x-koan",
    "skt" => "application/x-koan",
    "skm" => "application/x-koan",
    "latex" => "application/x-latex",
    "nc" => "application/x-netcdf",
    "cdf" => "application/x-netcdf",
    "sh" => "application/x-sh",
    "shar" => "application/x-shar",
    "swf" => "application/x-shockwave-flash",
    "sit" => "application/x-stuffit",
    "sv4cpio" => "application/x-sv4cpio",
    "sv4crc" => "application/x-sv4crc",
    "tar" => "application/x-tar",
    "tcl" => "application/x-tcl",
    "tex" => "application/x-tex",
    "texinfo" => "application/x-texinfo",
    "texi" => "application/x-texinfo",
    "t" => "application/x-troff",
    "tr" => "application/x-troff",
    "roff" => "application/x-troff",
    "man" => "application/x-troff-man",
    "me" => "application/x-troff-me",
    "ms" => "application/x-troff-ms",
    "ustar" => "application/x-ustar",
    "src" => "application/x-wais-source",
    "xhtml" => "application/xhtml+xml",
    "xht" => "application/xhtml+xml",
    "zip" => "application/zip",
    "au" => "audio/basic",
    "snd" => "audio/basic",
    "mid" => "audio/midi",
    "midi" => "audio/midi",
    "kar" => "audio/midi",
    "mpga" => "audio/mpeg",
    "mp2" => "audio/mpeg",
    "mp3" => "audio/mpeg",
    "aif" => "audio/x-aiff",
    "aiff" => "audio/x-aiff",
    "aifc" => "audio/x-aiff",
    "m3u" => "audio/x-mpegurl",
    "ram" => "audio/x-pn-realaudio",
    "rm" => "audio/x-pn-realaudio",
    "rpm" => "audio/x-pn-realaudio-plugin",
    "ra" => "audio/x-realaudio",
    "wav" => "audio/x-wav",
    "pdb" => "chemical/x-pdb",
    "xyz" => "chemical/x-xyz",
    "bmp" => "image/bmp",
    "gif" => "image/gif",
    "ief" => "image/ief",
    "jpeg" => "image/jpeg",
    "jpg" => "image/jpeg",
    "jpe" => "image/jpeg",
    "png" => "image/png",
    "tiff" => "image/tiff",
    "tif" => "image/tif",
    "djvu" => "image/vnd.djvu",
    "djv" => "image/vnd.djvu",
    "wbmp" => "image/vnd.wap.wbmp",
    "ras" => "image/x-cmu-raster",
    "pnm" => "image/x-portable-anymap",
    "pbm" => "image/x-portable-bitmap",
    "pgm" => "image/x-portable-graymap",
    "ppm" => "image/x-portable-pixmap",
    "rgb" => "image/x-rgb",
    "xbm" => "image/x-xbitmap",
    "xpm" => "image/x-xpixmap",
    "xwd" => "image/x-windowdump",
    "igs" => "model/iges",
    "iges" => "model/iges",
    "msh" => "model/mesh",
    "mesh" => "model/mesh",
    "silo" => "model/mesh",
    "wrl" => "model/vrml",
    "vrml" => "model/vrml",
    "css" => "text/css",
    "html" => "text/html",
    "htm" => "text/html",
    "asc" => "text/plain",
    "txt" => "text/plain",
    "rtx" => "text/richtext",
    "rtf" => "text/rtf",
    "sgml" => "text/sgml",
    "sgm" => "text/sgml",
    "tsv" => "text/tab-seperated-values",
    "wml" => "text/vnd.wap.wml",
    "wmls" => "text/vnd.wap.wmlscript",
    "etx" => "text/x-setext",
    "xml" => "text/xml",
    "xsl" => "text/xml",
    "mpeg" => "video/mpeg",
    "mpg" => "video/mpeg",
    "mpe" => "video/mpeg",
    "qt" => "video/quicktime",
    "mov" => "video/quicktime",
    "mxu" => "video/vnd.mpegurl",
    "avi" => "video/x-msvideo",
    "movie" => "video/x-sgi-movie",
    "ice" => "x-conference-xcooltalk"

    Couldn't find zip. try " header("Content-type: application/octet-stream\n");"
    S. Rosland

  7. #6
    Senior Member joncom11's Avatar
    Join Date
    Oct 2003
    Posts
    284
    Member #
    3532
    It can't be a problem with MIME because I haven't yet attempted using the .zip files that I wish to download. I am still using your original script, all I changed was the directory structure to fit my situation. Here are my files as I have them at the moment.

    test.html (the one which should start the download when clicking the image):

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </
    head>

    <
    body>

    <
    form name="form1" method="post" action="download_code.php">
              <
    input type="hidden" name="image" value="some_pic.jpg">
              <
    td ><input type='image' 
    src='some_pic.jpg' name='submit'></td></form>   


    </
    body>
    </
    html
    download_code.php (your script):

    PHP Code:
    <?php
    /* If the source is on an other server, you just replace the
    argument to fopen to "http://www.someserver.com/directory/subdirectory") */
    $fp fopen("$_POST['image'] ","r");

    //Set the max byte size
    $buff fread($fp,1500000);

    /*The "image/jpeg" can be replaced by a variable 
    containing file type as explained above. */
    Header("Content-Type: image/jpg");
    Header"Content-Disposition: attachment; filename=$_POST['image']");

    //Start output
    echo $buff;
    ?>
    These pages are both located in the same directory. The image that it uses for the link to begin the download is in the same directory.. and the image that it is trying to download is also in the same directory (it is the same image that it loads as the button). I still recieve the following error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/virtual/site127/fst/var/www/html/dltesting/download_code.php on line 4

    I don't think it's the "max file size" issue like it could have been because I'm still using the value you told me.... also, the files its trying to download does have read access and is not password protected or anything.... it is open to anyone that knows its url....

    thanks

    *******EDIT********

    oh ya.. you said you tried out the script already.. maybe could you send me those files and i'll see if they work on my server? could i contact you on msn or something?
    Pixel Fuse - Signature webpage, just a spashpage.
    Flash Frogger - Frogger remake, animated/coded in Flash (incomplete/discontinued)
    Daase Art Studio - Homepage of David Daase, a Canadian landscape artist - image gallery/showcase.
    More links if I think of some...

  8. #7
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    all I changed was the directory structure to fit my situation. Here are my files as I have them at the moment.
    Assuming you have written the script exactly as it's posted by you, then:
    <input type="hidden" name="image" value="some_pic.jpg">
    The "some_pic.jpg" has to be the actual name of the actual picture you're trying to download from your server. (obviously, it has to be a real jpeg image as well. The code provided is just an example with Pseudo names in the code.)
    $fp = fopen("$_POST['image'] ","r");
    Can't contain just the filename (i.e. $_POST['image']), but needs the complete URL including subdirectories to where your file resides.

    Example:
    $fp=fopen"www.mysitename.com/images/family/$_POST['image']/";
    where $_POST['image'] might contain for example "jack_fishing.jpg", which has to be a genuine file in that directory.

    If you want to download a HTML file, then in addition to reflecting that in the form-code, you will need to alter the Header to:
    PHP Code:
    //according to the supplied mime type table:
    Header("Content-Type: text/html"); 
    The error you're getting is simply telling you that the "fopen()" function expects a valid filepointer as it's argument, but is not recieving any!(It's a dead variable pointing nowhere)
    S. Rosland

  9. #8
    Senior Member joncom11's Avatar
    Join Date
    Oct 2003
    Posts
    284
    Member #
    3532
    the reason i used:

    $fp = fopen("$_POST['image'] ","r");

    instead of:

    $fp = fopen("http://someurl.com/files/$_POST['image'] ","r");

    is because the image is in the same directory as the download script.... even when I did have the full url.. it still gave me the error....

    *******EDIT***********
    I've been experimenting with it for about an hour now.... i can't seem the get it to work.. no matter where i tell it the file is located, no matter what i change, it doesn't seem to stop giving the same error.. coudl you please give me the files that you tested and worked? i could give you some ftp information to upload it to if you want....

    thanks
    Pixel Fuse - Signature webpage, just a spashpage.
    Flash Frogger - Frogger remake, animated/coded in Flash (incomplete/discontinued)
    Daase Art Studio - Homepage of David Daase, a Canadian landscape artist - image gallery/showcase.
    More links if I think of some...

  10. #9
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Just for the heck of it, try to write the filename in question directly into the code just to see if that works. If the file resides in the same folder, try to give it a complete adress like:""/home/YourAccessName/public_html/folder/file.ending";

    Also try to alter the header to "Content-type: application/octet-stream\n". That seems to force download of any filetype. (won't make any difference as long as your error type persists though)

    Maybe you can give your site adress, and I can try to download your index.htm/html file.

    If your files are accessed via ftp protocol, I think the script must be altered regardless of your ftp having anonymous access.
    S. Rosland

  11. #10
    Senior Member joncom11's Avatar
    Join Date
    Oct 2003
    Posts
    284
    Member #
    3532
    First off i'd just like to thank you for all the help you've given me so far... i realize that you must spend alot of time helping us dumber coders, so thanks i appreciate it...

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

    as for your suggestion... i've already tried doing the direct file thing. I used the:

    $fp = fopen("http://myfileshost.com/files/the_file_i_want.zip","r");

    and it seemed to work but i get yet another error:

    Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0 (tried to allocate 150000001 bytes) in /home/virtual/site127/fst/var/www/html/test.php on line 7

    .... i would give the site address but i'm a little concerned that search engines will pick up the domain address and when people search for my site in google, this post will show up, and people will be able to read about all the problems and even use the coding that i use on the site....
    Pixel Fuse - Signature webpage, just a spashpage.
    Flash Frogger - Frogger remake, animated/coded in Flash (incomplete/discontinued)
    Daase Art Studio - Homepage of David Daase, a Canadian landscape artist - image gallery/showcase.
    More links if I think of some...


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:24 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com