Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Hansi Schlegel
30 PointsHi Pilip G.. here's my question again, in more detail, regarding your post to from Jul 20, 2015, to Chetan
Hi Phlip G. I need to modify your gerat script. The max. file size must be 30MB and the target folder shoukd be "00/001". Tah you very much in advance for your help. Love Hansi. (Sorry for my poor english)
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> /* Script written by Adam Khoury @ DevelopPHP.com / / Modified by Philip Graf / / Video Tutorial: http://www.youtube.com/watch?v=EraNFJiY0Eg / / Edit Thread: https://teamtreehouse.com/forum/i-want-to-upload-video-file-with-progress-bar*/ function _(el){ return document.getElementById(el); } function uploadFile(){ var file = _("file1").files[0]; if(typeof file === "undefined") {
_("status").innerHTML = "ERROR: Please browse for a file before clicking the upload button";
_("progressBar").value = 0;
} else {
$.get('file_upload_parser.php?getsize', function(sizelimit) {
if(sizelimit > file.size) {
var formdata = new FormData();
formdata.append("file1", file);
formdata.append("size", file.size);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false);
ajax.open("POST", "file_upload_parser.php");
ajax.send(formdata);
} else {
var sizewarn = "ERROR: The File is too big! The maximum file size is ";
sizewarn += sizelimit/(1024*1024);
sizewarn += "MB";
_("status").innerHTML = sizewarn;
_("progressBar").value = 0;
}
});
}
} function progressHandler(event){ _("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total; var percent = (event.loaded / event.total) * 100; _("progressBar").value = Math.round(percent); _("status").innerHTML = Math.round(percent)+"% uploaded... please wait"; } function completeHandler(event){ _("status").innerHTML = event.target.responseText; _("progressBar").value = 0; } function errorHandler(event){ _("status").innerHTML = "Upload Failed"; } function abortHandler(event){ _("status").innerHTML = "Upload Aborted"; } </script> </head> <body> <h2>HTML5 File Upload Progress Bar Tutorial</h2> <form id="upload_form" enctype="multipart/form-data" method="post"> <input type="file" name="file1" id="file1"><br> <input type="button" value="Upload File" onclick="uploadFile()"> <progress id="progressBar" value="0" max="100" style="width:300px;"></progress> <h3 id="status"></h3> <p id="loaded_n_total"></p> </form> </body> </html>
<?php
/* Script written by Adam Khoury @ DevelopPHP.com / / Modified by Philip Graf / / Video Tutorial: http://www.youtube.com/watch?v=EraNFJiY0Eg / / Edit Thread: https://teamtreehouse.com/forum/i-want-to-upload-video-file-with-progress-bar*/
$ini_PostSize = preg_replace("/[^0-9,.]/", "", ini_get('post_max_size'))(1024*1024); $ini_FileSize = preg_replace("/[^0-9,.]/", "", ini_get('upload_max_filesize'))(1024*1024); $maxFileSize = ($ini_PostSize<$ini_FileSize ? $ini_PostSize : $ini_FileSize); $file = (isset($_FILES["file1"]) ? $_FILES["file1"] : 0);
if(isset($_GET["getsize"])) { echo $maxFileSize; exit;
} if (!$file) { // if file not chosen
if($file["size"]>$maxFileSize){
die("ERROR: The File is too big! The maximum file size is ".$maxFileSize/(1024*1024)."MB");
}
die("ERROR: Please browse for a file before clicking the upload button");
} if($file["error"]) {
die("ERROR: File couldn't be processed");
} if(move_uploaded_file($file["tmp_name"], "test_uploads/".$file["name"])){ echo "SUCCESS: The upload of ".$file["name"]." is complete"; } else { echo "ERROR: Couldn't move the file to the final location"; } ?>
1 Answer

Hansi Schlegel
30 PointsI have questions, to the graet script below. I need to modify filesize up to 30MB and file target-folder into "00/001". How can I do this`?
upload_form.html
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> /* Script written by Adam Khoury @ DevelopPHP.com / / Modified by Philip Graf / / Video Tutorial: http://www.youtube.com/watch?v=EraNFJiY0Eg / / Edit Thread: https://teamtreehouse.com/forum/i-want-to-upload-video-file-with-progress-bar*/ function _(el){ return document.getElementById(el); } function uploadFile(){ var file = _("file1").files[0]; if(typeof file === "undefined") {
_("status").innerHTML = "ERROR: Please browse for a file before clicking the upload button";
_("progressBar").value = 0;
} else {
$.get('file_upload_parser.php?getsize', function(sizelimit) {
if(sizelimit > file.size) {
var formdata = new FormData();
formdata.append("file1", file);
formdata.append("size", file.size);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false);
ajax.open("POST", "file_upload_parser.php");
ajax.send(formdata);
} else {
var sizewarn = "ERROR: The File is too big! The maximum file size is ";
sizewarn += sizelimit/(1024*1024);
sizewarn += "MB";
_("status").innerHTML = sizewarn;
_("progressBar").value = 0;
}
});
}
} function progressHandler(event){ _("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total; var percent = (event.loaded / event.total) * 100; _("progressBar").value = Math.round(percent); _("status").innerHTML = Math.round(percent)+"% uploaded... please wait"; } function completeHandler(event){ _("status").innerHTML = event.target.responseText; _("progressBar").value = 0; } function errorHandler(event){ _("status").innerHTML = "Upload Failed"; } function abortHandler(event){ _("status").innerHTML = "Upload Aborted"; } </script> </head> <body> <h2>HTML5 File Upload Progress Bar Tutorial</h2> <form id="upload_form" enctype="multipart/form-data" method="post"> <input type="file" name="file1" id="file1"><br> <input type="button" value="Upload File" onclick="uploadFile()"> <progress id="progressBar" value="0" max="100" style="width:300px;"></progress> <h3 id="status"></h3> <p id="loaded_n_total"></p> </form> </body> </html>
file_upload_parser.php
<?php
/* Script written by Adam Khoury @ DevelopPHP.com / / Modified by Philip Graf / / Video Tutorial: http://www.youtube.com/watch?v=EraNFJiY0Eg / / Edit Thread: https://teamtreehouse.com/forum/i-want-to-upload-video-file-with-progress-bar*/
$ini_PostSize = preg_replace("/[^0-9,.]/", "", ini_get('post_max_size'))(1024*1024); $ini_FileSize = preg_replace("/[^0-9,.]/", "", ini_get('upload_max_filesize'))(1024*1024); $maxFileSize = ($ini_PostSize<$ini_FileSize ? $ini_PostSize : $ini_FileSize); $file = (isset($_FILES["file1"]) ? $_FILES["file1"] : 0);
if(isset($_GET["getsize"])) { echo $maxFileSize; exit;
} if (!$file) { // if file not chosen
if($file["size"]>$maxFileSize){
die("ERROR: The File is too big! The maximum file size is ".$maxFileSize/(1024*1024)."MB");
}
die("ERROR: Please browse for a file before clicking the upload button");
} if($file["error"]) {
die("ERROR: File couldn't be processed");
} if(move_uploaded_file($file["tmp_name"], "test_uploads/".$file["name"])){ echo "SUCCESS: The upload of ".$file["name"]." is complete"; } else { echo "ERROR: Couldn't move the file to the final location"; } ?>