3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by natchattack
0

Hi,
You should read this tutorial: http://www.w3schools.com/PHP/php_file_upload.asp

The function you need to use is:

move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);

Or, you could open/create a file and put the data in it:

$fileHandle = fopen("upload/test.txt", "w");

fWrite($fileHandle, $data);
fClose($fileHandle);

Kieran :)

0

How to store a uploaded file in server side?

This is a simple method which does not check for file types or file size.

Create a form like this:

<form enctype="multipart/form-data" action="upload.php" method="POST">
choose a file: <input name="upload" type="file"/><br>
<input type="submit" value="upload"/>
</form>

Create a file upload.php as below.

// upload.php

$target_path = "files/";

$target_path = $target_path . basename( $_FILES['upload']['name']); 

if(move_uploaded_file($_FILES['upload']['tmp_name'], $target_path)) {
    echo "file ".  basename( $_FILES['upload']['name']). " has uploaded";
} else{
    echo "the file did not upload!";
}

This should upload a file of your choice into the given folder.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.