How to store a uploaded file in server side?

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 :)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.