Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2007
    Posts
    24

    Question Unanswered: How to open .pdf file without toolbar

    I am using php and I want to open .php file without showing
    any toolbar,statusbar, and no any menubar.
    I use following code to open .pdf file:

    <?php
    echo "<a href=$path target='_blank'>
    $FileName.pdf
    </a>
    ?>

    any body know the solution?

    - Vikrant

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Use javascript to open up a window without a toolbar etc.
    Why don't you want them to see a menu bar/etc?

  3. #3
    Join Date
    Apr 2007
    Posts
    24
    How to use it?
    I dont want to see user path of file i.e. Address bar.

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    The path of the file is always going to be written into the <a href=...> bit anyway so there's nothing to stop anyone from copying that. What you need to do is make sure that the PDF is NOT in the viewable domain. i.e. not in the htdocs folder, and instead is lower down in your directories.

    To use javascript to open a new window try :
    Code:
    <a href="#" onClick="window.open('$path','mywindowname',
        'width=400,height=200,toolbar=no,menubar=no,status=no')">
    $Filename.pdf
    </a>
    Also see : http://www.pageresource.com/jscript/jwinopen.htm for more syntax on using window.open javascript method.

  5. #5
    Join Date
    Apr 2007
    Posts
    24
    Thanks, it works fine in javascript, but I am not able to pass path, which is store in php variable $path, I am using scandir() in php to scan directory and show list of files, but it is not possible in javascript. and session variable is also not working here.
    may I use scandir type function in javascript??

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Vikrant_M
    ....
    may I use scandir type function in javascript??
    I don't know.. have you thought of trying it for yourself?
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Javascript is a client-side language, so in answer to your question... no.
    You already have the array of paths/files don't you? Else, how are you planning on outputting the link?

    What are you outputting at the minute? Do you have an example URL? Are you passing in the literal '$path' ?
    Make sure $path is being interpreted properly.
    In your PHP you are writing out the whole :
    <a href="#" onClick="window.open('$path','mywindowname',
    'width=400,height=200,toolbar=no,menubar=no,status =no')">
    $Filename.pdf
    </a>
    every time (as you iterate through your filelist), so just make sure $path is being interpreted.
    Code:
    echo '<a href="#" onClick="window.open(\''.$path.'\',\'mywindowname\',
        \'width=400,height=200,toolbar=no,menubar=no,status=no\')">
    '.$Filename.'.pdf';
    </a>

  8. #8
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    In order to clarify what i'm trying to say and give another example of how to echo (using " instead of ') :

    Code:
    <?php
    
    
    $path = "mypath/";
    $filename = "myfile";
    
    echo "<a href=\"#\" onClick=\"window.open('{$path}','mywindowname',
        'width=400,height=200,toolbar=no,menubar=no,status=no')\">
        {$filename}.pdf
    </a>";
    
    ?>
    Copy and paste the above code to see my working example.

  9. #9
    Join Date
    Apr 2007
    Posts
    24
    Thanks, It works very fine... only problem is when myfile.pdf opens in new window it is not showing 'mywindowname' it shows all the file path.
    is there any way to hide that path?
    ( I tried .htaccess RewriteRule to block url editing by user. this work on my computer very fine. but when I deploy it on main server, where we user Virtual hostting for site it not works!)

  10. #10
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    mod_rewrite needs to be enabled on your hosting environment. Might want to check that with your host. Very odd that it doesn't name the window correctly. Let me test my code

  11. #11
    Join Date
    Apr 2007
    Posts
    24
    The difference in my httpd.conf and main servers httpd.conf is main server useing virtual hosting. and so it not reading .htaccess file!

Posting Permissions

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