AJ_V Posted December 30, 2006 Share Posted December 30, 2006 Hi everyone! New to the forum due to the fact that I have just started learning PHP! I have currently done an upload script that I find works quite well, the script is written in PHP and will upload the file to the folder /upload/, make sure the file is under 5.5MB, add a random four digit number to all files uploaded to make them unique and change all files uploaded with the .php extension into .phps to prevent malicious execution. I would really like to implement an upload status bar on my website (http://www.vee-media.com), showing maybe the percentage of how much of the file has uploaded etc? Here is my script so far:[code]<?phpsession_start();$target = basename( $_FILES['uploaded']['name']) ;$ok=100;$target = str_replace(php,phps,$target);$random_digit=rand(0000,9999);$target = $random_digit.$target;if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){if ($uploaded_size > 5500000){echo "Your file is too large.<br>";$ok=0;}$_SESSION['filename'] = "http://vee-media.com/upload/$target";$URL="http://www.vee-media.com/uploaded.php";header ("Location: $URL");}else{$URL="http://www.vee-media.com/not_uploaded.html";header ("Location: $URL");}?>[/code]If you have experience with Windows Update, you have probably seen the scrolling green status bar - I am looking for something like that but with like a percentage or the amount of MB/KB already uploaded?Really grateful for any help!Regards,AJ.P.S Hope you all had a merry christmas and have a smashing new year! Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/ Share on other sites More sharing options...
trq Posted December 30, 2006 Share Posted December 30, 2006 Status bars and the like need to be handles client side using Javascript or something. However, if you search over at http://phpclasses.org Im sure Ive seen classes that handle this sort of thing. Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-149645 Share on other sites More sharing options...
AJ_V Posted December 30, 2006 Author Share Posted December 30, 2006 Thanks for ya help! Got it sorted now! Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-149666 Share on other sites More sharing options...
AJ_V Posted December 30, 2006 Author Share Posted December 30, 2006 Hi all! Got a bit of a problem with my upload script - it is all working fine except the file size limitation. When the user tries to upload something above 5.5MB, it should redirect to not_uploaded.php but instead it stays on the upload php file (php.php) and displays the following error:[b]Your file is too large.Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/cvenning/vee-media.com/upload/php.php:12) in /hsphere/local/home/******/vee-media.com/upload/php.php on line 17[/b]Here is the PHP script:[code]<?phpsession_start();$target = basename( $_FILES['uploaded']['name']) ;$ok=100;$target = str_replace(php,phps,$target);$random_digit=rand(0000,9999);$target = $random_digit.$target;if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){if ($uploaded_size > 5500000){echo "Your file is too large.<br>";$ok=0;}$_SESSION['filename'] = "http://vee-media.com/upload/$target";$URL="http://www.vee-media.com/uploaded.php";header ("Location: $URL");}else{$URL="http://www.vee-media.com/not_uploaded.php";header ("Location: $URL");}?> [/code]Any help is gratefully appreciated!Regards,AJ. Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-150046 Share on other sites More sharing options...
fert Posted December 30, 2006 Share Posted December 30, 2006 put ob_start(); at the very beginning of your script and ob_end_flush(); at the very end Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-150059 Share on other sites More sharing options...
AJ_V Posted December 31, 2006 Author Share Posted December 31, 2006 It doesnt' seem to do anything! Still comes up with the same error? Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-150448 Share on other sites More sharing options...
fert Posted December 31, 2006 Share Posted December 31, 2006 [code]<?phpob_start();session_start();$target = basename( $_FILES['uploaded']['name']) ;$ok=100;$target = str_replace(php,phps,$target);$random_digit=rand(0000,9999);$target = $random_digit.$target;if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){if ($uploaded_size > 5500000){echo "Your file is too large.<br>";$ok=0;}$_SESSION['filename'] = "http://vee-media.com/upload/$target";$URL="http://www.vee-media.com/uploaded.php";header ("Location: $URL");}else{$URL="http://www.vee-media.com/not_uploaded.php";header ("Location: $URL");}ob_end_flush();?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-150451 Share on other sites More sharing options...
wildteen88 Posted December 31, 2006 Share Posted December 31, 2006 Try:[code]<?phpsession_start();function redirect($URL){ header ("Location: $URL");}$target = basename($_FILES['uploaded']['name']) ;$ok = 100;$target = str_replace('php', 'phps', $target);$random_digit = rand(0000,9999);$target = $random_digit.$target;if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ if ($uploaded_size > 5500000) { echo "Your file is too large.<br>"; $ok = 0; } else { $_SESSION['filename'] = 'http://vee-media.com/upload/' . $target; $ok = 100; }}else{ $ok = 0;}if($ok != 100) redirect('http://www.vee-media.com/not_uploaded.php');else redirect('http://www.vee-media.com/uploaded.php');}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-150475 Share on other sites More sharing options...
AJ_V Posted January 2, 2007 Author Share Posted January 2, 2007 Thank you very much wild teen88! It is working perfectly now, I had to take out the final "}" because it gave a parse error but all is well now! Here is the final script:[code]<?phpsession_start();function redirect($URL){ header ("Location: $URL");}$target = basename($_FILES['uploaded']['name']) ;$ok = 100;$target = str_replace('php', 'phps', $target);$random_digit = rand(0000,9999);$target = $random_digit.$target;if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ if ($uploaded_size > 5500000) { echo "Your file is too large.<br>"; $ok = 0; } else { $_SESSION['filename'] = 'http://vee-media.com/upload/' . $target; $ok = 100; }}else{ $ok = 0;}if($ok != 100) redirect('http://www.vee-media.com/not_uploaded.php');else redirect('http://www.vee-media.com/uploaded.php');?>[/code]Now, anyone know how I could integrate a upload status bar to show what percentage has uploaded?! Regards,AJ Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-151086 Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 Um... didn't I allready answer that? Either edit this topic back to its original subject or start a new thread, this one is way OT. Quote Link to comment https://forums.phpfreaks.com/topic/32246-if-file-above-55mb-redirect-to-not_uploadedphp-it-doesnt-though/#findComment-151090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.