Page 1 of 1

choosing own directory for receiving uploaded file in linux

PostPosted: 09. September 2007 08:23
by asheesh
hi all
i just install XAMPP in scientific linux and make a page for uploading files. my receiving page is like this
Code: Select all
<?php
$uploaddir = getcwd();
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (file_exists("" . $_FILES["userfile"]["name"])) {
    echo $_FILES["userfile"]["name"] . " already exists.\n ";
    echo "please select different name and send!";
} else {
    echo '<pre>';
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "<h2>File is valid, and was successfully uploaded.<h2>\n";
    } else {
        echo "Possible file upload attack!\n";
    }
}
?>

rather than using $upload_dir= getcwd();
how can i give path to receive uploaded file in my prefered directory
waiting.....

PostPosted: 09. September 2007 12:02
by Wiedmann
Sorry, but I don't really understand your problem...

rather than using $upload_dir= getcwd();

getcwd() just returns a string with the current directory path. And then you set the value of the variable $uploaddir to this string.

how can i give path to receive uploaded file in my prefered directory

You can also store any other string value (with a directory path) in this variable, like:
Code: Select all
$uploaddir = '/your/prefered/directory/';


1st BTW:
Code: Select all
$uploaddir = getcwd();

This must be:
Code: Select all
$uploaddir = getcwd() . '/';


2nd BTW:
Code: Select all
if (file_exists("" . $_FILES["userfile"]["name"])) {

This must be:
Code: Select all
if (file_exists($uploadfile)) {