This is a very 'bare-bones' file uploader. It will take the file you specify, and upload it to your server.
You will need to create 2 new pages. One called 'uplaoder.php' (this is the page with the HTML formatting and whatnot), and one called 'upload.php' (this page will hold the PHP coding that does the uploading).
HTML:
PHP:
If you wish to rename the files, be certain that the 'form action=' int he HTML page is set to the correct file name for the page holding the PHP coding.
*Note: this will not upload a file larger than 100MB in most cases. Many web hosts limit the file size you can upload in the php.ini file and many times you do not have access to this file. Sometimes the file size will be even smaller that 100MB, check with your host before trying to upload and large files so you don't waste your time trying to upload a 100MB file when your hosts only allows 50MB sized files to be uploaded.
You will need to create 2 new pages. One called 'uplaoder.php' (this is the page with the HTML formatting and whatnot), and one called 'upload.php' (this page will hold the PHP coding that does the uploading).
HTML:
Code:
<form action="upload.php" method="post" name="add-form" enctype="multipart/form-data">
<label for="file">
<div align="center"></div>
</label>
<div align="center"></div>
<div align="center">
<p class="style1">Max upload file size: 100MB<br />
<br />
<span class="style2">Choose a File:</span><br />
<input type="file" name="file" id="file" />
<br />
<input type="hidden" name="action" value="add" />
<!-- Hidden input type -->
<input type="submit" name="submit" value="Upload" />
</p>
</div>
</form>
PHP:
PHP:
<?php
if(isset($_POST['submit'])) {
if($_POST['action'] == 'add') {
// Folder where the file will be uploaded.
$upload_path = './uploads/' . $_FILES['file']['name'];
// Checks if the file already exists in the folder.
if(!file_exists($upload_path)) {
// Check the size of the file.
if($_FILES['file']['size'] < 100000000000 && $_FILES['file']['size'] > 0) {
// If there are any errors.
if($_FILES['file']['error']) {
echo "Error: " . $_FILES['file']['error'];
} else {
// Success!
echo "File successfully uploaded.<br /><br />";
echo "The filename is: <strong>" . $_FILES['file']['name'] . "</strong><br />";
echo "The filesize is: <strong>" . $_FILES['file']['size'] . "</strong><br />";
echo "The filetype is: <strong>" . $_FILES['file']['type'] . "</strong><br />";
// Move uploaded file to upload folder.
move_uploaded_file($_FILES['file']['tmp_name'], $upload_path);
}
} else {
echo $_FILES['file']['size'] < 1 ? 'Incorrect filename.' : 'File size is too big';
}
} else {
echo "File already exists in your folder. ";
}
}
}
?>
If you wish to rename the files, be certain that the 'form action=' int he HTML page is set to the correct file name for the page holding the PHP coding.
*Note: this will not upload a file larger than 100MB in most cases. Many web hosts limit the file size you can upload in the php.ini file and many times you do not have access to this file. Sometimes the file size will be even smaller that 100MB, check with your host before trying to upload and large files so you don't waste your time trying to upload a 100MB file when your hosts only allows 50MB sized files to be uploaded.


