SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

PHP 5 file upload with register_global off

File upload part 1
In PHP 5 and above as the global variable is kept as off we can't access the uploaded file and related information by the way we handled in PHP 4. All uploaded file and its connected information will be available in an array.

$_FILES[file_up];


So to get the file size we have to use

$_FILES[file_up][size]


Note that in the form we have used the input filed name as file_up. Same way all other information can be collected.

$_FILES[file_up][type]
$_FILES[file_up][tmp_name]
$_FILES[file_up][error]


By using this way here is the code for displaying the form.

<FORM ENCTYPE="multipart/form-data" ACTION="uploadck.php" METHOD=POST>
Upload this file: <INPUT NAME="file_up" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File"></FORM>


Here is the code to handle file upload.

<?
$file_upload="true";
$file_up_size=$_FILES['file_up'][size];
echo $_FILES[file_up][name];
if ($_FILES[file_up][size]>250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
$file_upload="false";}

if (!($_FILES[file_up][type] =="image/jpeg" OR $_FILES[file_up][type] =="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload="false";}

$file_name=$_FILES[file_up][name];
$add="upload/$file_name"; // the path with the file name where the file will be stored, upload is the directory name.
if($file_upload=="true"){

if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)){
// do your coding here to give a thanks message or any other thing.
}else{echo "Failed to upload file Contact Site admin to fix the problem";}

}else{echo $msg;}
?>


Discuss this tutorial at forum


Further readings
Reading from local and remote files by using fopen()
Writing to a file by fwrite() function
unlink:Deleting file by using unlink function
Deleting all files present inside a directory
Downloading files using header control
File upload to server using PHP
File upload using PHP 5 and register_global off
Uploading More than one file to server
Displaying all files and directory of a folder
Getting the Present file name running the PHP script
Getting the last updated time of the file in PHP
Displaying the last modification time of the file
Searching for text within a pair of tags of a html page
Listing All title tags inside a directory














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.