Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 04-03-2007, 11:56 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Question PHP + HTML FORM video upload.

Ok so all I want to do is be able to upload some information using an html form including some videos. (1 at a time in each upload) then strip the filename from c:\whatever\myvideo.fla to myvideo.fla and store and store all the info in my database minus the video which will be stored in a "videos" folder.

The SQL stuff isn't the hard part but when using plain old HTML FORMs and POST (I included ENCTYPE="multipart/form-data" in the form tag) the script simple times out leaving me looking at a blank screen. Is there a better way of doing this without taking the expensive commercial route?

P.S. I have no problems passing string info from html to php and uploading to the database.

2 problems are;

1. Uploading the videos successfully (2-3mb).

2. stripping the file name to just the file i.e. myvideo.fla

Any help would be greatly appreciated. I'm so stumped!!

Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 04-04-2007, 01:30 AM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default Re: PHP + HTML FORM video upload.

1) If you don't have a PHP script to handle the upload it will still work (You should setup a script to alteast check if the file already exists and for file extension), but it won't check anything about the file, and it will be uploaded to the same folder at the html page used to upload it.
As to why it is timing out it is most likely an issue with the server settings. I know I was working on a script for someone else and it was timing out on any file over the size of 7mb.

2) It should just be uploading the filename.extension, if for some reason when you upload a file it is giving you the full location on your local hard drive then you will need to rename the file once its uploaded.

You can do something like

$file = $_POST['filename'];
$new_name = substr($file, strrpos($file, '/')+1, strlen($file));
rename($file, $new_name);

Where $file is the name on the server (the one that contains the full local hd path), and $new_name is the filename.extension extracted from that path.
__________________

Register/Login Script
Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 04-04-2007, 08:03 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,346
Default Re: PHP + HTML FORM video upload.

Use Advanced BlueVoda Form Processor . It will do excactly what you want. It will store the info in the database, it will upload the files in any folder you like (you name it) and it will strip ypur local hard disk path from the path name leaving only the actual filename.extension.

We have not usually had timeouts, if not for very large files. It has been working with mp3's of 6 - 7 Mb, so i beleive that you will have no problem.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 04-04-2007, 01:25 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Thumbs up Re: PHP + HTML FORM video upload.

Thanks for the mega quick replies!! And I will definitely be checking that script out Naval! I don't think the issue is with the server settings. I checked using phpinfo() a few days ago. max file size is 20mb, memory_limit is 40mb and timeouts were set nice and high.

Strange as hell.. Oh and thanks for the procedure to strip the local name down to just the name and extension!

I'll give this all a whirl and see how i get on.

Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 04-04-2007, 02:28 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Default Re: PHP + HTML FORM video upload.

Ok I looked at ABVFP and it's just what i'm looking for in the long run or maybe just not what i was expecting or there's probably more of a 90% chance that I'm using it incorrectly!

I realise I am maybe not giving the best description of what I need help with. Because my english is attrocious... despite being from the UK :)

substr($file, strrpos($file, '/')+1, strlen($file)); answers one question. I tested it to see what the outcome would be and it's perfect for one of my problems.

Has anyone got a simple script that I can include in my current php to correctly upload a video to my webserver which is being passed from an html form using POST?

addTutorial.php will have a form of structure, 4 text inputs (no problem) and 2 file inputs. 1 is a small image about 30kb or so.. (no problem posting this!!) and the other a flash video of about 2-3mb. This does not require much validation as the person that will be using the form will have a certain amount of training by myself!

Is there a simple function to complete this task? Or is it going to be complicated no matter what way I approach it?

Thanks

Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 04-04-2007, 04:21 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default Re: PHP + HTML FORM video upload.

Heres a shortened down version of an upload script ive used in the past.

Note: I made some changes, and i didnt test, it may need some debugging.

PHP Code:
<?
$ext_list 
= array(".zip",".rar",".wmv",".avi",".mpg",".mpeg",".wma",".m4a",".ogg",".gif",".bmp",".jpg",".jpeg",".png",".psd",".tga",".xcf",".fla",".swf",".txt",".sql",".doc",".rtf",".xls",".pp",".dwg",".exe");

$a_name $_FILES["a_file"]["name"];            // holds the name of the file uploaded from the client
$a_type $_FILES["a_file"]["type"];            // holds the mimetype of the uploaded file
$a_size $_FILES["a_file"]["size"];            // holds the size in bytes of the uploaded file
$a_tmp $_FILES["a_file"]["tmp_name"];            // holds the name of the temporary copy of the file stored on the server
$a_error $_FILES["a_file"]["error"];            // holds any error code resulting from the file transfer

$ext strrchr($a_name,'.');
$filePath $upload_dir.'/'.$a_name;

if(!
is_dir($upload_dir))
{
    echo 
'The directory to upload the files doesn\'t exist';
}
elseif(!
is_writable($upload_dir))
{
    echo 
'The directory to upload the files is NOT writeable';
}
elseif(
file_exists($upload_dir.$a_name))
{
    echo 
'File Already Exists - Rename Your File';
}
elseif(!
$a_name)
{
    echo 
'You Must Select A File To Upload';
}
elseif(
$size $size_bytes)
{
    echo 
'File Too Large, File must be smaller then <b>$kb</b> KB';
}
elseif((!
in_array($ext,$ext_list)))
{
    echo 
'You Cannot Upload A File With That Extension - Put It In A Zip File And Try Again';
    require_once(
"template/upload.php");
}
elseif(!
move_uploaded_file($a_tmp$filePath))
{
    
$error 'Error When Uploading The File.<br>'.$a_error;
}
else
{
    
// Insert Into Database

    
if($db_query)
    {
        echo 
"File Successfully Uploaded And Added To Database";
    }
    else
    {
        echo 
"Error Uploaded, But Not Added To Database - Contact An Admin";
        
// database error delete file
        
unlink($filePath);
    }
}
?>
also, one the function i gave you to strip the path to the file.ext, make sure you change the '/' to a '\', i tested with a URL not a C:\ path.
__________________

Register/Login Script
Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 04-04-2007, 07:00 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Talking Re: PHP + HTML FORM video upload.

I'm trying this out right now. You have no idea how much this would save my skin if it worked!!

I'll be very very greatful... Either way I'll let you know how it goes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 04-04-2007, 08:53 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,346
Default Re: PHP + HTML FORM video upload.

It might seem that i insist on using ABVFP, but i think you would save your self some time by doing so.
ABVFP wil upload the file(s), it will send you the message, it will store the info in the database (not the files themselves, though it can be easily modified to also store the files), and will also provide several validations. Furthermore, your own work is limited to installing the script and setting up your form.

I also don't understand what you mean by "or probably i'm using it incorrectly".

And why should you use the "substr($file, strrpos($file, '/')+1, strlen($file))" ?

ABVFP as well as Watdaflip's script, both use the file name without including the path, so there should be nothing to strip.

Or maybe i have misread your post ?
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old 04-04-2007, 09:00 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Default Re: PHP + HTML FORM video upload.

Ok here's what I have... I haven't even tested it yet because I know it's full of bugs.. I'm useless at combining my scripts with someone elses!

PHP Code:
<?php 

session_start
(); 

if (
$_SESSION['loggedin'] == "true"){

$title $HTTP_POST_VARS['title'];
$dateAdded $HTTP_POST_VARS['dateAdded'];
$tuning $HTTP_POST_VARS['tuning'];
$content $HTTP_POST_VARS['contents'];
$video $HTTP_POST_VARS['video'];
$tab $HTTP_POST_VARS['tab'];

$db mysql_connect("****""*******""********");
mysql_select_db("*********",$db);
    
$dbQuery="SELECT * FROM *******";
$result mysql_query($dbQuery,$db);

$numPosts 1;
    
while (
$arrayVar=mysql_fetch_array($result)) {
    
$numPosts $numPosts 1;
}

$videoDir "../videos";
$tabsDir "../tabs";



$fileName $_FILES["video"]["name"];            // holds the name of the file uploaded from the client
$fileType $_FILES["video"]["type"];            // holds the mimetype of the uploaded file
$fileSize $_FILES["video"]["size"];            // holds the size in bytes of the uploaded file
$fileTmp $_FILES["video"]["tmp_name"];            // holds the name of the temporary copy of the file stored on the server
$fileError $_FILES["video"]["error"];            // holds any error code resulting from the file transfer

$filePath $videoDir."/".$fileName;

if(
$fileSize 4000000)
{
    echo 
"File Too Large, File must be smaller then <b>4</b> MB";
}
elseif(!
move_uploaded_file($fileTmp$filePath))
{
    
$error "Error When Uploading The File.<br>".$fileError;
}
else
{
    
// Insert Into Database

    
if($db_query)
    {
        echo 
"File Successfully Uploaded And Added To Database";
    }
    else
    {
        echo 
"Error Uploaded, But Not Added To Database - Contact An Admin";
        
// database error delete file
        
unlink($filePath);
    }
}



$tabName $_FILES["tab"]["name"];            // holds the name of the file uploaded from the client
$tabType $_FILES["tab"]["type"];            // holds the mimetype of the uploaded file
$tabSize $_FILES["tab"]["size"];            // holds the size in bytes of the uploaded file
$tabTmp $_FILES["tab"]["tmp_name"];            // holds the name of the temporary copy of the file stored on the server
$tabError $_FILES["tab"]["error"];            // holds any error code resulting from the file transfer

$tabPath $tabsDir."/".$tabName;

if(
$tabSize 100000)
{
    echo 
"File Too Large, File must be smaller then <b>100</b> KB";
}
elseif(!
move_uploaded_file($tabTmp$tabPath))
{
    
$error "Error When Uploading The File.<br>".$tabError;
}
else
{
    
// Insert Into Database

    
if($db_query)
    {
        echo 
"File Successfully Uploaded And Added To Database";
    }
    else
    {
        echo 
"Error Uploaded, But Not Added To Database - Contact An Admin";
        
// database error delete file
        
unlink($tabPath);
    }
}




$dbQuery="INSERT INTO ****** VALUES ('$numPosts', '$title', '$dateAdded', '$tuning', '$fileName', '$tabName', '$content')";
$result mysql_query($dbQuery,$db);

echo 
"<Script>alert('Tutorial submitted and now available on Fret-tastic!');window.location=\"fretAdmin.php\";</script>";

}

else { 
$_SESSION['loggedin'] = "false"; echo "<script>javascript:alert('out ye go!!'); window.location='************';</script>"; }

?>
SCRATCHING HEAD VIGOROUSLY!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old 04-04-2007, 09:01 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Default Re: PHP + HTML FORM video upload.

I don't know navaldesign.... I'm genuinely at my wits end... I think I take on too much some times....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old 04-05-2007, 10:26 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default Re: PHP + HTML FORM video upload.

only issue I see is at

if($db_query)

that line is checking if the query to add the information to the database worked give success message, otherwise delete the fail and give failure message. You don't have a query called $db_query, and also you query to add to the database is after both file uploads.
__________________

Register/Login Script
Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old 04-06-2007, 01:03 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Default Re: PHP + HTML FORM video upload.

Yeah I need to change those bits and pieces I know but all in all you think this should work? A few friends have suggested converting the video to a bit stream and storing the video directly in the database.

Does anyone know much about this or does this sound like a bad idea?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old 04-06-2007, 01:13 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,346
Default Re: PHP + HTML FORM video upload.

You can do whatever you want: store the file in the database, or simply upload it, or both. It's up to you.

As Watdaflip was saying, the only problem here is that you have this piece of code

Quote:
else
{
// Insert Into Database

if($db_query)
{
echo
"File Successfully Uploaded And Added To Database";
}
else
{
echo
"Error Uploaded, But Not Added To Database - Contact An Admin";
// database error delete file
unlink($filePath);
}
}


which is not needed there. This should check the database updating and give an error message, but, where you have it, it is not only useless, but it will also cause a problem, as $db_query doesn't yet exist at that point.

__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old 04-06-2007, 03:14 PM
Private First Class
 
Join Date: Apr 2007
Posts: 8
Talking Re: PHP + HTML FORM video upload.

All this help has been incredible! I wish I had of known about this place sooner. I haven't got it working yet altogether but I'm sure I can with all the info here.

I have one final question (couldn't find an answer on php.net).

How do I convert a video to a bitstream, how large is it gonna be and what format would I need to make the field in my table on the database to hold it?

All help has been great here. If you ever need any flash help drop me an email!! =)

Thanks

Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools