Virtual Path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Virtual Path

Post by abdul »

Hi all..

I want all my uploaded files in another file system than the one the site is running. When I pass the absolute path as argument for move_uploaded_file function, everything is working fine. But, I want to use relative path. For that I have created a new alias called "userUploads" in apache. But, when I use this in the same function it is returning error. I know, to get the absolute path from a relative path there is a function called Server.MapPath in ASP. Is there any equivalent function in PHP. The main reason I am insisting on virtual path is the difference in file system of our test and live servers. Here is the working code.

Code: Select all

$Path= "/rw-root/data/b2bsite/userUploads/" . $_FILESї'ImageFile']ї'name'];
		
if (is_uploaded_file($_FILESї'ImageFile']ї'tmp_name'])) 
   move_uploaded_file($_FILESї'ImageFile']ї'tmp_name'],$Path);
When I change the $Path as

Code: Select all

$Path= "/userUploads/" . $_FILESї'ImageFile']ї'name'];
The upload fails. :cry: Any help will be appreciated.

Thanks in advance.

-Abdul
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

try "./userUploads/"
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Post by abdul »

MeOnTheW3 wrote:try "./userUploads/"
Sorry, no luck. But, thanks for replying.

-Abdul
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

RE:Virtual Path

Post by abdul »

I still couldn't solve this. Any more suggestions..?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

try usin the realpath() function: http://www.php.net/manual/en/function.realpath.php
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Post by abdul »

mydimension wrote:try usin the realpath() function: http://www.php.net/manual/en/function.realpath.php
I tried it before I ask this question. But, it returns an empty string rather than the absolute path.

This returned only "RealPath="

Code: Select all

echo ("RealPath=". realpath ("/userUploads/"));
Thanks anyway.

-Abdul
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

what about:

Code: Select all

echo ("RealPath=". realpath ("./userUploads/"));
realpath() is meant to expand . and ..
not to mention that in "/userUploads/" there is no path to expand, it is an absolute path.
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Post by abdul »

Still the same. It returns nothing. Let me also tell you there is no issue in the alias set-up in apache as the HTML below works fine.

Code: Select all

<img src="/userUploads/image1.jpg">
Cheers!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

There was this advice from the user comments on realpath() which may be useful:
php manual wrote:If you're running PHP as Apache module, you can use apache_lookup_uri() to translate virtual paths and filenames to real ones.
Mac
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Post by abdul »

Thank you Mac, But, The "filename" method of apache_lookup_uri() object retruns the absolute path of the current directory, irrespective of the parameter supplied. I think this is useful, only if the file is in the current directory. But, my file is not in the directory where the current file is being executed.

Cheers!

-Abdul
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Post by abdul »

For the time being I have solved this by assigning a variable for my absolute path (On a generic include file) and manually changing it when uploading the files onto the production server. But, I feel difficult to believe PHP doesn't have a function to handle this. Any more suggestions..?

Cheers!

-Abdul
Post Reply