Php File System

I have problem handling the php filing system and want to ask certain question

[size=10pt]Question 1.[/size]
Is it Possible to Upload a File to a folder on a level above than the php file

For EG:-
The location of upload.php is root/function/file/upload.php
and syntax be
[php]
if (file_exists(“root/” . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . " already exists. ";
}
else
{
move_uploaded_file($_FILES[“file”][“tmp_name”], “root/” . $_FILES[“file”][“name”]);
echo "Stored in: " . “root/” . $_FILES[“file”][“name”];
}
[/php]
But the problem is i am unable to upload a file to folder which is at a higher level than the directory of upload.php file

I want to Upload a file to root

[size=10pt]Question 2.[/size]
Is It Possible to Download a file from a folder which is at a higher level

Here is the Example
I want to Download root/file/iwant.php

and to do that i want to execute the file down.php (location root/function/file/down.php)
the syntax i was able to use was
[php]

<?php //the php file you wish to download... $file_name = 'root/file/iwant.php'; header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file_name)); readfile($file_name); ?>

[/php]
but this wont work because of the location problem i think

i apologize if i am not able to make myself clear , if u want i can try to explain a little better.
Please Let me Know Asap

Regards

As long as the web server user has access to write to the folder you can upload files there.

In order to move up one directory you should use double dots.

Say you are in /home/web/xgurux/mysite/, and you want to refer to a file one level above:
[php]if (file_exists("…/" . $_FILES[“file”][“name”])) {
echo ‘exists!’;
}[/php]

You could also hard code the full path
[php]if (file_exists("/home/web/xgurux/mysite/" . $_FILES[“file”][“name”])) {
echo ‘exists!’;
}[/php]

[hr]

Note the use of the first slash.

/folderThis will refer to a folder in the root of the drive

folderThis will refer to a folder inside the folder you are already in

Sponsor our Newsletter | Privacy Policy | Terms of Service