Here, I'll show you how to upload files to the server by your browser.

upload.php:

CODE

<?
$sizelimit = "280000"; // file size limit
$patch = "/home/yoursite/public_html/files"; // patch to where the uploaded files will be saved - change it

if($file != ""){ // if $file is set
$file_ext = explode(".",$file_name); // check for the extension

if($file_size > $sizelimit) // check if file size is bigger than the limit
die("This file is too big.");

if(($file_ext[1] == "exe") && ($file_ext[1] == "bat")) // check for invalid files: add how extensions you want
die("File extension forbidden!");

if(file_exists("$patch/$file_name")) // check if this file is already in your server
die("There is another file with the same name in this server!");

if($file_ext[2]) // file.hi.exe - it is for security that this files will not be uploaded
die("Invalid file name!");

$title = stripslashes($title); // security reasons
$file_name = stripslashes($file_name); // security reasons
$file_size = stripslashes($file_size); // security reasons
$description = stripslashes($description); // security reasons

if(@copy($file,"$patch/$file_name")) // if the file has been suceful uploaded
die("
<p align=\"center\">The file has been uploaded!<br><Br>
<a href=\"index.php\">Back to the main page</a><br>
<a href=\"upload.php\">Send another file</a>
</p>
"); // show this message
}else{ // if the file isn't set, show the form
?>
<form action="<? echo "$PHP_SELF"; ?>" method="post" enctype=multipart/form-data>
<table border="0">
<tr>
<td width="100">File:</td>
<td><input type="file" name="file" size="30"></td>
</tr>
</table>
<p align="center">
<input type="submit" value="Send file">
</p>
</form>
<?
}
?>


Well here we are! It can be used for an "Send your file" pages for members, but remember that this code can be dangerous if not used with security. I hope this code don't create much problems just like my topic with an login sistem, but, if u find any problems, post it here.

Thx

 

 

 


Reply