Contact Us

Scripts: Php :: File upload operations >> Library Article #1

Developer's Section

Upload a File Using PHP
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3798)

Learn simpe techniques to upload a file using PHP.

In this script tutorial we will learn how to upload a file using php.

Let's start with the php:

 Code Snippet 1

<? //upload a file in php

    $uploadError = "";

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

    $temp_name = $_FILES['uploadedfile']['tmp_name'];

    if(basename( $_FILES['uploadedfile']['name']) == "")
        $uploadError = "There was an error processing your request.              
        $uploadError .= "Please Try Again!";

        $uploadError = "The File: ";
        $uploadError .= basename( $_FILES['uploadedfile']['name']);
        $uploadError .= " already exists in the system";

    if(move_uploaded_file($temp_name, $target_path)) 
        echo "File:" . $_FILES['uploadedfile']['name'] . "<br />";
        echo "Size:" . $_FILES['uploadedfile']['size'] . "<br />";
        echo " has been uploaded";

After you have the php in place you can create a simple form like this:

 Code Snippet 2

<form name="upload_file" enctype="multipart/form-data"  
 method="POST" action="your_script.php">
<table border="0">
       <td width="50">File:</td>
       <td><input name="uploadedfile" type="file" /></td>
       <td colspan="2">
       <input type="Submit" name="Submit" value="Upload">

if you want to increase the max file size for eveydownload you can add the following input field to the form described above:

 Code Snippet 3

<!-- put this inside the form tags -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />

See other Scripts in File upload operations

Submit Your Scripts:

System Message:
  • Your PHP script has been sent. Please allow 48 hours for processing.

If you would like to have your PHP scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]