Need help with making a .pdf available

Discussion in 'Web Design and Development' started by Platonist, Sep 25, 2007.

  1. Platonist macrumors member

    Platonist

    Joined:
    Nov 3, 2006
    #1
    Hello All,

    As the title suggests, I need help getting a .pdf accessible via a link that can be on multiple sites. I know this might sound vague, but being new to web design/development I don't know if there is technical terminology for such phenomena. What I have to do is make one .pdf file available for download by mulitple sites. Ideally, it would be a link of some sort so that each site would not have to upload the .pdf, due to the fact that this .pdf file will be updated on a regular basis. So, what I would like to do is set something up whereby each site can post a link that will lead to an instant download of the current file (i.e. it wouldn't just lead to another site where they would click another link to download the file). Is this possible? What would one need to do this?

    If this isn't clear, please ask questions. This is something that I really have to get going soon, so any help is greatly appreciated.

    Many Thanks!
     
  2. kiffles macrumors newbie

    Joined:
    Jul 4, 2007
    Location:
    Southport
    #2
    Hi Platonist,

    We needed something similar and came up with this in PHP:

    PHP:

    class downloader {

        private 
    $path$filename$allowed_domains = array(), $real$bad_ref$filesize;

        function 
    __construct($rl$pth$fle) {

            
    $this->path $pth;
            
    $this->filename stripslashes($fle);
            
    $this->real $rl;
            
    $this->filesize filesize($this->real.$this->path.$this->filename);
            
    $this->allowed_domains[0] = "alloweddomains.com";
            
    $this->bad_ref "yourerrorpage.php";

        }

        private function 
    domain_check() {

                if (isset(
    $_SERVER['HTTP_REFERER'])) {

                    
    $referer $_SERVER['HTTP_REFERER'];
                    list(
    $remove$stuff) = split('//'$referer2);
                    list(
    $domain$stuff) = split('/'$stuff2);

                    if(
    in_array($domain$this->allowed_domains) != "1") {

                        
    header("Location:".$this->bad_ref);
                        exit();

                    }

                }

        }

        private function 
    download_file() {

            if(!
    is_file($this->real.$this->path.$this->filename)) {

                
    header("Location:error.php");
                exit();

            } else {

                    
    header("Pragma: no-cache");
                    
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    
    header("Cache-Control: private");
                    
    header("Content-Description: File Transfer");
                    
    header("Content-Transfer-Encoding: binary");
                    
    header("Content-Type: application/octet-stream");
                    
    header("Content-Disposition: attachment; filename=\"".$this->filename."\"");
                    
    header("Content-Length: ".$this->filesize);

                    
    readfile($this->real.$this->path.$this->filename);

                 }

        }

        public function 
    execute() {

            
    $do_domain $this->domain_check();
            
    $do_downloaded_file $this->download_file();

        }


    }

    and then make your link point to a php page with:
    PHP:
    require("linktoabovecode.php");
    $fle = new downloader($domain$folder$filename);
    $do_fle $fle->execute();
    The script wont let the person know where the pdf is located so you can put it on all your sites that need to link to the one pdf.

    I'm not sure how up to date the above code is as we didn't get to finish this site as the software developer still hasn't finished their product. :(

    If this is of any help please let me know.
     
  3. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
    #3
  4. Platonist thread starter macrumors member

    Platonist

    Joined:
    Nov 3, 2006
    #4
    Thanks for the feedback. As it stands, I don't know a whole lot about the coding -- I put together a site using iWeb and I have the .pdf available there for now. I am not sure how I would go about putting the file in a certain place within my domain and making a link to that place. Would this entail doing something within iWeb or is iWeb a hindrance here? I do have afs space available, but I am still trying to figure out if I can use that in this whole mess. I supposedly have a "public" folder in my afs space but I am not yet clear on how to use it via the web.

    Further thoughts?

    p.s. Thanks for bearing with a neophyte!
     
  5. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
    #5
    You need some public web space, whatever it is, so you can ftp into. From their you can give people the URL to the file location.
     

Share This Page