By 23/02/2016 13 Comments

How To Upload Files In PHP?

  • Open php.ini and write the following code in it for file upload configuration.

file_uploads = On
upload_max_filesize = 10M
post_max_size = 50M

Example: index.html

<!Doctype html>
<form method = "POST" action = "upload.php" enctype="multipart/form-data">
<input type="file" name="file_name"><br/><br/>
<input type="submit" value="Submit">

Example: upload.php

$file = $_FILES["file_name"]["name"];
$location = $_FILES["file_name"]["tmp_name"];
$file = file_upload($file, $location);
if(is_file_uploaded($location, $file))
 echo "file successfully uploaded";
 echo "file could not be uploaded";

function file_upload($name, $location){
 $new_file_name = strtolower($name);
 $final_file = str_replace(' ', '-', $new_file_name);
 return $final_file;

function is_file_uploaded($location, $final_file){
 // don't forget to create "uploads" folder for uploaded files.
 if(move_uploaded_file($location, "uploads/".$final_file))
 return true;
 return false;

Posted in: HTML, PHP, Solutions

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .