Results 1 to 4 of 4

Thread: why isn't the following working?

  1. #1
    Join Date
    Jan 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question why isn't the following working?

    hi ppl,
    cant figure out why the following isn't working, im trying to let a user download a file only once, now the download file message comes up but the pdf reader say's its corrupt/illegal...please help

    Script 1:

    PHP Code:
    <?php
    include( "class.DatabaseConnect.php" );
        
    session_start( );


        
    $check=$_GET['des'];
        
        
    $dbConn = new DatabaseConnect( );
            
    $dbConn->connect"workdb" );
        
    $sqlResult8 
                
    $dbConn->executeQuery("select downloaded from design_tbl where pdf_path='$check'");
                
    $temp8mysql_fetch_array($sqlResult8);
                
    $pdf=$temp8['downloaded'];
        
        if(
    $pdf==0)
        {
        
    sqlResult9 
                
    dbConn->executeQuery("update design_tbl set downloaded=1 where pdf_path='$check'");
        
        
    $file $_GET['file'];
    header('location:getit.php?f='.$file.'');
        }
        
        if(
    $pdf==1)
        {
        echo 
    "File already downloaded, contact system admin";
        
        }
    ?>
    second script the above script redirects to:
    PHP Code:
    <?php
    header
    ('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename=mydesign.pdf');
    readfile($_GET['f']);
    ?>

  2. #2
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    Your script is fine.. But I think the problem is with the file name....

    Try echoing $file or just look at the url and see what it says after file=

    This file should exist in the same folder where your second script getit.php is stored...

    Even if the file doesn't exist, it will still download an unreadable pdf file, and if you open that file in a notepad, you will see a php error in the format given below:

    <br />
    <b>Warning</b>: readfile(filename.pdf) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>[name of the php file]</b> on line <b>4</b><br />
    Last edited by borris83; 04-24-2009 at 12:08 PM.

  3. #3
    Join Date
    Jan 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by borris83 View Post
    Your script is fine.. But I think the problem is with the file name....

    Try echoing $file or just look at the url and see what it says after file=

    This file should exist in the same folder where your second script getit.php is stored...

    Even if the file doesn't exist, it will still download an unreadable pdf file, and if you open that file in a notepad, you will see a php error in the format given below:

    <br />
    <b>Warning</b>: readfile(filename.pdf) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>[name of the php file]</b> on line <b>4</b><br />
    thanks,
    tried that and get the following:

    Code:
    <br />
    <b>Warning</b>:  readfile(a***e.o*****k.co.uk/users/3/designs/1239024562.pdf) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>/usr/home/n****e/public_html/clients/o*****k/a****e/getit.php</b> on line <b>5</b><br />
    why is this so? i know the file exists (i've *** out the url for dataprotection reasons )

    and why is it giving me two different URL's?, the first one is what get's given to the $file... the directory structure is as so:



    do i need to code the $file URL differently?

  4. #4
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    try saving the file in this directory:

    /usr/home/n****e/public_html/clients/o*****k/a****e/

    Because this is where the php script is looking for the file...

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
  •