choosing own directory for receiving uploaded file in linux

Problems with the Linux version of XAMPP, questions, comments, and anything related.

choosing own directory for receiving uploaded file in linux

Postby asheesh » 09. September 2007 08:23

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.....
asheesh
 
Posts: 8
Joined: 29. August 2007 07:37

Postby Wiedmann » 09. September 2007 12:02

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)) {
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 6 guests