Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 17th, 2008, 04:56 PM
Authorized User
Join Date: Jan 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default choose between two directories and use one

i have something like this

$dir = array("http://www.asdf.com/files", "/var/www/html/videos");

how can i check both to see if a certain file exist in one of the two directories, and use whicheverone has it.

if both have the same file, then always use the first directory $dir[0]

I tried using foreach($dir as $directory) {} but all the url end up becoming


where did the Array/ appear from ?

also, I have header(location:"http://www.asdf.com/file). how can i make it check both directories and choose whichever one has the specific file, if both have it, then put priority over the asdf.com directory.

thank you.

Old June 3rd, 2008, 05:07 PM
Authorized User
Join Date: Sep 2007
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post

What you have should work?

foreach ($dir as $directory) {
   \\here you want to echo out directory not dir
   echo $directory .'<br />'
   \\you can check if the file/directory exists
   \\with the functions is_file() or is_dir()
   \\check php.net for usage

free wifi | http://localwifisearch.com
web dev | http://mynameissteve.com

Similar Threads
Thread Thread Starter Forum Replies Last Post
root directories BrendonMelville Linux 2 December 14th, 2006 08:44 AM
External Directories doyle matt Apache Tomcat 0 October 19th, 2004 09:13 AM
choosing directories joconnor PHP How-To 0 August 11th, 2004 09:12 AM
Sub Directories shmacgregor VS.NET 2002/2003 2 December 19th, 2003 05:18 PM
Drives and Directories zhenwe1 Servlets 1 December 14th, 2003 01:45 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.