...

View Full Version : Absolute Paths



RHolm
06-01-2004, 07:12 AM
Hi all,

I'm trying to upload images to a server, but the absolute paths are creating headaches.

right now i have: $path = "d:\nuvocreative\userimages\wheelquip\";

But that returns as: d: uvocreative\userimages\wheelquip\ and i have to have a space after the last \ or or the " doesn't show up.

Does anyone have any ideas?

carl_mcdade
06-01-2004, 07:24 AM
The \ is an escape character so you are unintentionally escaping the last quote. Try


$path = "d:\\nuvocreative\\userimages\\wheelquip\\";

or


$path = "d:/nuvocreative/userimages/wheelquip/";

At tip if you are using the sam code on a developement windows machine then uploading to a Unix/Linux machine. Use the root then append it with the path inbetween the working folder. This way the same variable will always contain the right path.



$path = $HTTP_SERVER_VARS['DOCUMENT_ROOT']. /directory/folder/;


either should work.

RHolm
06-01-2004, 07:29 AM
Thanks.. it was $path = "d:\\nuvocreative\\userimages\\wheelquip\\";

Now that's the first problem down, with one more to go.



$tmp_file = $HTTP_POST_FILES['userfile']['tmp_name'];
$new_file = $path.$HTTP_POST_FILES['userfile']['name'];
$res = copy($tmp_file,$new_file);


is returning Warning: copy(d:\nuvocreative\userimages\wheelquip\commodore.jpg): failed to open stream: No such file or directory in d:\nuvocreative\clients\wheelquip\imageupload.php on line 19

carl_mcdade
06-01-2004, 07:59 AM
d:\nuvocreative\userimages\wheelquip\commodor e.jpg

The part in bold is missing ffrom your path. Assuming that

\nuvocreative\userimages\wheelquip\ is your root directory if you use that tip I gave then all your problems should be solved.

RHolm
06-01-2004, 08:10 AM
Yer.. the file is called commodore.jpg and for some reason it had a space between the commodor and the e.jpg

That part is fixed now, but i still get the same error.

Warning: copy(d:\nuvocreative\userimages\wheelquip\commodore.jpg): failed to open stream: No such file or directory in d:\nuvocreative\clients\wheelquip\imageupload.php on line 19

Ok.. i don't know why it is, but the error message doesn't have the space between the commodor and the e.jpg, but when i put it in here, it says it does..

carl_mcdade
06-01-2004, 08:12 AM
I can still see that space in the path. Close you browser and empty the cahche so that you get a fresh page. Check you filename to make sure everything is in lowercase. You might even try and rename the file and give it a go.

RHolm
06-01-2004, 08:19 AM
But the error isn't displaying the space until i put it in here.



Temp File: d:\PHP\uploadtemp\php88A.tmp
New File: d:\nuvocreative\userimages\wheelquip\commodore.jpg

Warning: copy(d:\nuvocreative\userimages\wheelquip\commodore.jpg): failed to open stream: No such file or directory in d:\nuvocreative\clients\wheelquip\imageupload.php on line 18
Upload Failed!


That's the whole page

RHolm
06-01-2004, 08:20 AM
there is no space, i don't get what's with these forums

carl_mcdade
06-01-2004, 10:38 AM
Is the folder you are trying to copy to CHMOD 777? ie. Has write previleges

RHolm
06-01-2004, 11:38 PM
It wasn't.. and no wi'm trying to set it as that.. but i've never done it before, so i'm having trouble.. i'm going to paste the whole code in and see if someone can help me



<?
$path = "d:\\nuvocreative\\userimages\\wheelquip\\";
$max_size = 200000;

chmod($path, 777);

if (!isset($HTTP_POST_FILES['userfile'])) die ("No image selected.");

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) { die("The file is too big<br>\n"); }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {

if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { die("The file already exists<br>\n");}
$tmp_file = $HTTP_POST_FILES['userfile']['tmp_name'];
$new_file = $path.$HTTP_POST_FILES['userfile']['name'];
print "Temp File: ".$tmp_file."<br>";
print "New File: ".$new_file."<br>";

$res = copy($tmp_file,$new_file);

if (!isset($res)) { die("Upload Failed!<br>"); }
echo "Upload Sucessful<br>\n";

echo "File Name: ".$path.$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { echo "Wrong file type<br>\n"; exit; }

}
?>

RHolm
06-01-2004, 11:43 PM
Ok.. i solved it. I always do that, spend all day trying to work something out, come in to work the next morning, and i get it straight away. the folder was called "wheelquipsql", not "wheelquip".

carl_mcdade
06-02-2004, 12:04 PM
Ok.. i solved it. I always do that, spend all day trying to work something out, come in to work the next morning, and i get it straight away. the folder was called "wheelquipsql", not "wheelquip".

Happens too me more than I would like it to. This is a very big club. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum