![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Moderator, TSF Articles
|
File Uploader script for Your website
Hi people
![]() This PHP script is aimed to make your website have a great feature of a uploader so people can easily upload files/images to your hosting servers without and hassle. First of all, we need to have a look at the code. Code:
<?php
/*************************************************
* Created By Hosting-Town.com
* Open to use for anyone
* CopyRight must remain in place
* Hosting-town.com
****************************************************/
//Upload Locacation E.G. ./uploads/
$uploadLocation = "./";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Uploader!</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
font-size: 10px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div id="main">
<div id="caption">UPLOAD FILE</div>
<div id="icon"> </div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data">
File to upload:<center>
<table>
<tr><td><input name="upfile" type="file" size="36"></td></tr>
<tr><td align="center"><p><br/>
<input class="text" type="submit" name="submitBtn" value="Upload">
</p>
<p align="right" class="style1"><a href="http://hosting-town.com">Made By Hosting-Town.com - James Addison </a></p></td>
</tr>
</table></center>
</form>
<?php
if (isset($_POST['submitBtn'])){
?>
<div id="caption">RESULT</div>
<div id="icon2"> </div>
<div id="result">
<table width="100%">
<?php
$target_path = $_SERVER['DOCUMENT_ROOT'] . '/mp3s/' . basename( $_FILES['upfile']['name']);
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
echo "The file". basename( $_FILES['upfile']['name']).
"has been sucessfully uploaded.";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
</table>
</div>
<?php
}
?>
<div>
Please note: You are solely responsible for any content that you may choose to upload to this site. The site owner/administrator will not accept ANY responsibility regarding illegal content that you upload. Should you not agree to these terms, please leave this page now.
</body>
*Please note that there is currently no file restrictions on this script so anyone visiting your site will be able to upload any type of file of any size* Now, open the above in your favourite text editor, such as notepad and change the area in bold in the code to the location as to where you want the files to be uploaded to. For example: If you want all uploads go to a folder called /uploads you would make the code look like: Code:
$target_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/' . basename( $_FILES['upfile']['name']); Also, remember to make sure that your uploads folder has full write permissions (CHMOD 777). Now, you will be able to test the script by going to the URL where you uploaded the PHP file. If successful, the script will tell you its successful by showing: The file (your filename) has been successfully uploaded. This script can be used openly by anyone as long as the full copyright markings stay in place. Please bear in mind, this script was written in our own time for free for you. |
|
|
![]() |
| Thread Tools | |
|
|