Beginner to PHP. How do I create a Video file upload?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
daniel_mintz
Forum Newbie
Posts: 3
Joined: Tue Mar 13, 2007 7:17 pm

Beginner to PHP. How do I create a Video file upload?

Post by daniel_mintz »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Background
I am using Dreamweaver and have a MySQL database and PHP web server running. I am a beginner to all of this but enjoying immensely.

Problem.
I have inserted some code to a form on a php page to do a file upload as below.

[syntax="html"]<form enctype="multipart/form-data" action="_URL_" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>
I do not know the following to make this work.

1) What should the url be in the code above?
2) Is the file stored in the My SQL database or is it just uploaded to my web server for example in the public_html folder? 3) How do I account for this in a database table entry if i want ot corss reference which users have uploaded what?

Bit confused how to make this work and trying not to buy a PHP uploader software if possible?

Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post by Kadanis »

1. the url should be the page with your code in it that will do something with the forms data. it could be calling the same page with some logic to decided if the form has been submitted or not, or it could be a different page entirely.

2. the file itself is uploaded to the /tmp/ directory on your webserver and given a temporary name. the details of this upload are held in the $_FILES variable, which you can use in your script page (see number 1).

a simple way of dealing with the upload would be:

Code: Select all

$temp_file = $_FILES['userfile']['tmp_name'];

$user_file = $FILES['userfile']['name'];

$user_file_name = basename($user_file);

$path_to_my_uploads = '';

if (move_uploaded_file( $temp_file , $path_to_my_uploads . $user_file_name ) {
  //file upload success
  //run a sql insert on the uploads table to add this upload and the user that uploaded.
} else {
  //file upload failed
}
Obviously, this is only a loose example, the $_FILES and form submission would need to be validated to make sure you have data to use, you would need a destination path and should have some form of error handling on the upload, but it should get you started.

Edit-->
Sorry didn't see question 3.

3. The easiest way to reference this in the database would be to have an uploads table, then just write an entry with the users ID and the file name. You could put a hidden field in the form containing the users ID so that it becomes part of the form post data, then just run a SQL INSERT on a successful upload

You could store the file itself as a BLOB in the database but this leads to large database records depending on how many uploads you are expecting, and what file size they are.
daniel_mintz
Forum Newbie
Posts: 3
Joined: Tue Mar 13, 2007 7:17 pm

Post by daniel_mintz »

Thanks that is really helpful. It may seem like a real novice question but I am having trouble working out what the destination path should be? Any pointers. It is not local_host so I was wondering if it was my public_html folder but this didn't seem to work either. Any tips?
Post Reply