Log in

View Full Version : Video Upload Form



pssparkman
11-01-2007, 02:26 AM
I have an upload form that works well for small files but when I try to upload video files of a large size it times out. How can I edit this so that I can upload say 100-150MB video files no problem.


<?php
$upload_dir = "uploads/";

$num_files = 5;
//the file size in bytes.
$size_bytes =104857600; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".mpeg",".wav",".avi",".zip",".exe");


//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist. Please see a Teamwork Administrator for assistance.");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777). Please see a Teamwork Administrator for assistance.");
}


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

echo "<h3>Upload results:</h3><br>";

//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {

//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];

#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#

if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br><br>";
}else{
#-----------------------------------------------------------#
# this code will check file extension #
#-----------------------------------------------------------#

$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. Please see a Teamwork Administrator for assistance.<br><br>";
}else{
#-----------------------------------------------------------#
# this code will check file size is correct #
#-----------------------------------------------------------#

if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be no larger than <b>100 MB</b> in size. Please see a Teamwork Administrator for assistance.<br><br>";
}else{
#-----------------------------------------------------------#
# this code check if file is Already EXISTS. #
#-----------------------------------------------------------#

if(file_exists($upload_dir.$file_name)){
echo "File $i: ($file_name) already exists. Please see a Teamwork Administrator for assistance.<br><br>";
}else{
#-----------------------------------------------------------#
# this function will upload the files. :) ;) cool #
#-----------------------------------------------------------#
if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) has been uploaded successfully. A Teamwork Administrator has been notified of the upload, Thank You!<br><br>";
}else{
echo "File $i: Faild to upload. Please see a Teamwork Administrator for assistance.<br><br>";
}#end of (move_uploaded_file).

}#end of (file_exists).

}#end of (file_size).

}#end of (limitedext).

}#end of (!is_uploaded_file).

}#end of (for loop).
# print back button.
echo " <br><a href=upload.php><input type=\"button\" name=\"back\" value=\"Back\"></a> <a href=media.html><input type=\"button\" name=\"redirect\" value=\"Finish\"></a> ";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo " <h3>Select files to upload!</h3>
Max File Size = 100 MB<br>
Allowed File Types = gif, jpg, jpeg, mov, wav, avi, zip";
echo " <br><br><br><br> <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" size=\"70\" name=\"file". $i ."\"><br><br>";
}
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<blockquote>
<br><br>
<input type=\"submit\" name=\"upload_form\" value=\"Upload\"> <input type=\"reset\" name=\"reset\" value=\"Reset\"> <a href=media.html><input type=\"button\" name=\"redirect\" value=\"Cancel\"></a>
<br><br>PLEASE ONLY PRESS UPLOAD ONCE!<br>The upload may take time to complete.
</blockquote>
</form>";
}
?>

Either a solution to edit this to work with such large files or another way to upload these large video files to an ftp server in the same way that this form is created. I want to be able to do this within an html web page or a php web page.Is this possible? I know very little about this and would like any help possible. Thanks.

pssparkman
11-01-2007, 07:32 PM
Anyone know how to change this upload script so that I can upload large video files to an ftp server but keep it in the same format as what is there if possible?

insanemonkey
11-01-2007, 07:49 PM
you have to do it thru ftp

look here
http://www.dynamicdrive.com/forums/showthread.php?t=25477

pssparkman
11-01-2007, 08:32 PM
Yeah, I have been looking at that thread for some time, but don't know how to incorporate it into my own. Or know the approach of using it with the current file upload script above. Any suggestions?

insanemonkey
11-01-2007, 08:40 PM
uhm well make a ftp account add in the details.. and, the only thing is i dont know how to post the urll etc...

just play around with it and see what you get...

pssparkman
11-01-2007, 08:51 PM
I don't know jack about php and coding such as this. I am a noob, got an steps or maybe a place for me to start.

insanemonkey
11-01-2007, 08:53 PM
well take the code(the updated version) put it into a file
called- upload.php

then insert your information for the ftp, if you made an account..
then goto yourdomain.com/upload.php

then try uploading something and then tell me if you see the file that you uploaded on your server..., if you get an error let me know and i will help you..

pssparkman
11-01-2007, 09:02 PM
Sure, I will give it a try when I can. I am not at a computer that I can do code a the moment. Also the code in the post above, is that the "updated version" you are talking about? If it is, it doesn't look complete. If you want me to put FTP information into my code in the first post, I don't know how or know what to put, sorry. Or do I insert that code in the other forum thread into mine somewhere?

I am sorry, I don't mean to be so stupid at this.

insanemonkey
11-01-2007, 09:02 PM
I cant seem to get it working either ill ask jas.. to give me source and see..

pssparkman
11-01-2007, 09:12 PM
I cant seem to get it working either ill ask jas.. to give me source and see..

Thanks for the help, and hope to hear from you when I can.

blm126
11-01-2007, 11:10 PM
This isn't a problem with your script. This is a problem with the configuration of PHP. If you have access to the php.ini file(or equivalent), you need to change PHP's post_max_size and upload_max_filesize and possibly max_input_time. This is possible in PHP code by adding these lines


ini_set('post_max_size','500M');//Upload up to 500 Megabytes
ini_set('upload_max_file_size','500M');//Upload up to 500 Megabytes


Hope that helps.

insanemonkey
11-02-2007, 06:58 AM
What if we dont have access to the php.ini file :(

insanemonkey
11-03-2007, 04:09 AM
You can set the value also directly inside the php-script via
<? ini_set("session.gc_maxlifetime","10800"); ?>


try this..

pssparkman
11-03-2007, 05:11 AM
You can set the value also directly inside the php-script via
<? ini_set("session.gc_maxlifetime","10800"); ?>


try this..


Okay so I need to add this piece of code to my script to allow for large video size uploads say up to about 150MB, if so where do I add it? It will work. I am a bit lost with the last few posts by the two of you and don't quite understand fully, sorry I don't know jack about .php coding and this type of stuff.

blm126
11-04-2007, 05:18 PM
You can set the value also directly inside the php-script via
<? ini_set("session.gc_maxlifetime","10800"); ?>


try this..
What? That is the entirely wrong setting to change. If you read my first post, you'll see that included that the correct code when I first posted.

Okay so I need to add this piece of code to my script to allow for large video size uploads say up to about 150MB, if so where do I add it? It will work. I am a bit lost with the last few posts by the two of you and don't quite understand fully, sorry I don't know jack about .php coding and this type of stuff.
Okay, where you see

<?php
change it to


<?php
ini_set('post_max_size','150M');//Upload up to 150 Megabytes
ini_set('upload_max_file_size','150M');//Upload up to 150 Megabytes

pssparkman
11-04-2007, 06:39 PM
Okay, sorry. I will give it a try. Also, I don't have a php.ini, the only php page in my server is this scrip that I am running. So what do I do with it if I don't have access to the php.ini.

On another note, could you explain it in short what it will allow for large video uploads?

blm126
11-05-2007, 10:14 PM
Okay, sorry. I will give it a try. Also, I don't have a php.ini, the only php page in my server is this scrip that I am running. So what do I do with it if I don't have access to the php.ini.

On another note, could you explain it in short what it will allow for large video uploads?

No, you don't make the changes to php.ini(that is another method to fix this problem). You adjust it right in your script.

Basically, PHP itself limits the size uploads can be. This is to ease server resources. So, PHP, by default, rejects any files bigger than 8MB(maybe it is 16MB). All we need to do is modify the PHP configuration, and the script should allow larger uploads(though it will take a long time). There is several ways to change the PHP configuration. One is through php.ini(possible on some hosts), another is trhough .htaccess, and the final way is in the PHP script itself. The third method is the one I gave you directions for. Guess that isn't too short of an explanation....

pssparkman
11-05-2007, 10:44 PM
Hey as long as the explanation is explained clear enough. Nothing is too long.

Jas
11-07-2007, 06:03 PM
I cant seem to get it working either ill ask jas.. to give me source and see..

If you still want it, my script is here (http://www.dynamicdrive.com/forums/showthread.php?t=26422).

pssparkman
11-07-2007, 06:08 PM
Thanks, I am going to see if it will work with what I need. Is there anyway to incorporate the ftp connection for the large video upload into the script I have here on the first post of this thread? If not, I was just wondering.

Jas
11-07-2007, 06:28 PM
I think it's best not to with that type of upload. FTP is used for large uploads.

Great error checking on your script though. Seems to really analyze the new file, eh?

pssparkman
11-07-2007, 07:32 PM
I wouldn't mind the comment on the script, but it isn't mine. I found it somewhere in the forums. But hey, thanks to them.