View Full Version : relative path from upload_tmp_dir root folder?
01-06-2006, 04:06 PM
ini_get('upload_tmp_dir') returns "PHP\uploadtemp" on my server. This is a relative path from some known folder.
move_uploaded_file takes two parameters that are relative paths from this known folder.
the first can be gotten easily... it's $_FILES["file"]["tmp_name"]
the second needs to be constructed like
where $relativePath is "www/localhost/music/" for my server...
this is the relative path from the known folder to my current directory.
My Question is as Follows:
how can I obtain $relativePath dynamically so as to allow my code to run on different servers?
01-06-2006, 04:21 PM
01-06-2006, 04:56 PM
that's outputting : C:/Documents and Settings/Charlie/Desktop/no hassle php/PortableWebAp3.1/program/www/localhost
whereas, I only want the relative path to document root: www/localhost
thanks for the attempt though
01-06-2006, 04:59 PM
for only a relative path, can you just use this? "music/"
01-06-2006, 05:33 PM
Ithought I could, but it seems that for the purposes of moving temporary upload files to an actual location, you need to use a relative path from the folder one level above www/
unfortunately, I want to be able to package my code for use on other servers... who might run it in various subdirectories... and I'm not certaing that all servers work the same way.
the worst part is that it doesn't seem to allow the use of absolute paths.
01-06-2006, 06:02 PM
ok,, best I could come up with is this:
$path = $_SERVER['REQUEST_URI'];
$result = str_replace($page,"",$path);
//give the function the current page name
hope this helps,
01-06-2006, 07:11 PM
The file upload example at PHP.net uses an absolute path, on windows 98 the spaces in the path might be an issue though not on XP etc, can you post upload/move code ?
01-06-2006, 07:12 PM
did this function work?
I never had a chance to test it,
01-06-2006, 07:43 PM
sorry angst, I just tested it... it outputs "/" ... i'll retry using absolute paths
01-06-2006, 07:55 PM
I think I have the solution... I was dumb...
when trying absolute paths, I wrote:
I'll try editing my code, and get right back to you:.....
ok, it works now... if anyone's still interested, here's my final (ugly) code:
$uploadDir = "files/";
$mydir = "/music/";
$i = 1;
$temp = $uploadDir;
$simplename = basename( $_FILES['file']['name']);
$uploadDir = $temp.$i;
$uploadFile = $uploadDir.$simplename;
echo "the file was not uploaded correctly, try again";
$uploadPath = $_SERVER['DOCUMENT_ROOT'].$mydir.$uploadFile;
echo "sucessful upload to $preamble.$uploadFile";
echo "error moving file from ".$_FILES["file"]["tmp_name"]." to $preamble.$uploadFile";
01-06-2006, 08:07 PM
not that bad,
just beautify it a little,
tabbing and what not;-)
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.