1

What is this code doing?

<?php
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
}
?>
2
  • 1
    I can't help but something tells me this is another homework :) Commented Mar 21, 2011 at 15:28
  • @fabrik: hopefully not, this code is not really secure. Commented Mar 21, 2011 at 16:20

5 Answers 5

1

It is basically uploading a file and echoing the target file's name.

There should also be something like an HTML form to send the file to this script.

Sign up to request clarification or add additional context in comments.

4 Comments

Where is it uploading the file?
@Calvin Han: To the value of the variable $_REQUEST['folder']. This value should be send with the request. Do you also have some code like <form> .. some code .. </form>?
It's uploading the file to the document root - which is where the php file is and it is getting a folder name from the request.
@Calvin Han: Did I answer your question or do you need to know anything else?
1

It accepts an user uploaded file, and puts it in your webroot in a folder, specified by the user. Then it outputs the path of the uploaded file.

Comments

0

This code is to upload a file in the destination directory. Is there anything else do you want to understand.

This will upload the file in the path you have in variable $_REQUEST['folder']

Comments

0

Storing files uploaded (possibly via HTML form) onto server.

Comments

0

It's accepting a file posted by a HTML form and uploading it to a certain directory within a server. After that it's displaying the location of the file on screen (in the browser).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.