Page 1 of 1

Virtual Path

Posted: Thu Nov 14, 2002 7:35 am
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

Posted: Thu Nov 14, 2002 3:03 pm
by MeOnTheW3
try "./userUploads/"

Posted: Fri Nov 15, 2002 3:42 am
by abdul
MeOnTheW3 wrote:try "./userUploads/"
Sorry, no luck. But, thanks for replying.

-Abdul

RE:Virtual Path

Posted: Thu Nov 21, 2002 3:36 pm
by abdul
I still couldn't solve this. Any more suggestions..?

Posted: Thu Nov 21, 2002 5:40 pm
by mydimension
try usin the realpath() function: http://www.php.net/manual/en/function.realpath.php

Posted: Fri Nov 22, 2002 3:42 am
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

Posted: Fri Nov 22, 2002 7:10 am
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.

Posted: Fri Nov 22, 2002 8:23 am
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!

Posted: Fri Nov 22, 2002 9:34 am
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

Posted: Sun Nov 24, 2002 4:02 pm
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

Posted: Fri Nov 29, 2002 4:49 pm
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