Solved

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

Posted on 2012-03-29
4
374 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 look for a specific file type in a local or remote server directory using PHP.

759 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

20 Experts available now in Live!

Get 1:1 Help Now