PHP: Upload Files to the Server

With PHP, it is simple to upload any file to your server.

<?php
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES[‘uploadedfile’][‘name’]);

if(move_uploaded_file($_FILES[‘uploadedfile’][‘tmp_name’], $target_path)) {
echo “The file “. basename( $_FILES[‘uploadedfile’][‘name’]). ” has been uploaded”;
} else{
echo “There was an error uploading the file, please try again!”;
}?>

The form used to apply this uploading:

<form enctype="multipart/form-data" action="uploader.php" method="POST"^gt;
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />
Upload File: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>


if (!window.netshel_ord) { netshel_ord=Math.random()*10000000000000000;
}
if (!window.netshel_tile) { netshel_tile=1; }
document.write(‘<script language=”JavaScript” src=”http://ad.doubleclick.net/adj/ns.techrecipes/programming;sz=728×90;tile=’+netshel_tile+&#8217;;ord=’ + netshel_ord + ‘?” type=”text/javascript”></scr’ + ‘ipt>’);
netshel_tile++;

I suggest implementing a password (php) protection on this page to ensure noone other than the administrator can upload files. Missuse of uploading can surpass a server’s space and cause fines or bans of site owners. So be careful.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: