Home
Credits
Affliates
Link Exchange

HTMLshaman
PHPshaman
LINUXshaman

Helpful Links
Web Design Images
Backgrounds
Icon Sets
GIF Images


Simple Scripts : File Upload

PHP can also be used for uploading of files directly to your server online and reduces the need for you to log into FTP or do it on the SHELL.

However, do bear in mind that it uses the Apache Daemon to do it and what ever permission rights the Apache Daemon has, the script's loaded file will have too and can be dangerous if not carefully monitored.

Before we present to you the script the following is the danger of having it running on your site unmonitored and the risks involved.

If the HTTPD ( Apache Daemon ) is set to run as a root user and have root rights to your system, a user can upload a SHELL, PERL or even another PHP script.
But remember that this file is loaded by the root user and will have root rights to the system because for the simple fact that the HTTPD is the same level as the root user, if this script is excuted and runs SHELL commands to delete all files in the system, example issue the "exec ("rm -R /*");" line in the script, the system will think that its the root user doing it and will wipe out everything that is in your system and leaving no trace of it.

Now that you know the risk involved, please proceed with caution and below is the sample upload file script that is coded in both PHP and HTML.

<html>
<head>
<title>Sample Upload Script</title>
</head>
<?php
// Below must be the absolute path to the directory
$file_dir = "/location/to/the/directory/to/load/files";
// Below is the URL fo the directory
$file_url = "http://www.domain.com/upload/directory";

foreach( $HTTP_POST_FILES as $file_name => $file_array )
{
print "path: ".$file_array['tmp_name']."<br>\n";
print "name: ".$file_array['name']."<br>\n";
print "type: ".$file_array['type']."<br>\n";
print "size: ".$file_array['size']."<br>\n";

if ( is_uploaded_file( $file_array['tmp_name'] ) && $file_array['type'] == "image/gif" )
{
move_uploaded_file( $file_array['tmp_name'], "$file_dir/$file_name") or die ("File cannot be copied");
print "<img src=\"$file_url/$file_name\"><p>\n\n";
}
}
?>
<body>
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="25600">
<input type="file" name="fupload"><br>
<input type="submit" value="Upload File">
</form>
</body>
</html>






Basics
Introduction
Compilation for Apache

Language Intro
The Basics
Structuring
Script Flow
Functions
Arrays
Objects

Extras
Global values

Simple Scripts
MySQL Query
File Upload
List Contents






Disclaimer:
Contents on this site is provided for educational purposes and will not be distributing source codes from any major commercial reference.
Partial code may be used to provide better understanding of how the program works or functions to illustrate to the reader more clearly.
Other programs that are provided freely on the internet may be placed as a quick solution to the user's needs taking in consideration that it is not altered in any way.

Our Recommended Links
prepaid phone card
Online Casino
Smiley Central
Ventrilo Servers
Counter-Strike Servers
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
phone card

Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Hollywood Lyrics
Resident Evil
Contact us at webmaster@galacnet.com for advertising opportunities on GalacNet.