Solved

Open pdf file in new window from one of two folders with php

Posted on 2012-03-29
4
375 Views
Last Modified: 2012-08-13
I have two folders, one with pdf files starting with P in the Place folder, and the other with files starting with C in the Country folder.

If I use a link like
<a target='_blank' href='http//myhost.com/sort.php?trip=$row[trip_number]'>" . $row['trip_number'] . "</a>  

And than in the sort.php script use this
$trip = (isset($_GET["trip"])) ? $_GET["trip"] : 0;

What can I use to take the $_GET["trip"] and redirect the request to the right folder and open the file in the parent window. I was thinking that the if statement might work like

if $trip = p*.pdf than redirect to place/$trip, if not redirect to country/$trip and if it cant find the file echo not on file and not the 404

but as you see I have no idea how to write it. Also any other way of doing this is fine if you have one. This is all I could come up with....  Thanks
0
Comment
Question by:GD_GRAY
  • 2
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 37783414
$dir="country/";
if(preg_match('/^p/i',$trip)){$dir="place/";}
0
 

Author Comment

by:GD_GRAY
ID: 37783866
Sorry to ask but how would I put that into play ?
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 500 total points
ID: 37784050
in the php script which is called by the links
0
 

Author Closing Comment

by:GD_GRAY
ID: 37784332
Wow, your the bomb. thank you . I set the redirect up to use $dir/$trip and got what i need,
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now