Difference between revisions of "PHP-and-MySQL/C4/File-Upload-Part-2/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{|Border=1 !Time !Narration |- |0:00 |Welcome back. In the first part of this tutorial, I showed you how to take out specific properties of our uploaded file using this form her…')
 
Line 1: Line 1:
 
{|Border=1
 
{|Border=1
!Time
+
|'''Time'''
!Narration
+
|'''Narration'''
 
|-
 
|-
|0:00
+
|00:00
 
|Welcome back.  In the first part of this tutorial, I showed you how to take out specific properties of our uploaded file using this form here.
 
|Welcome back.  In the first part of this tutorial, I showed you how to take out specific properties of our uploaded file using this form here.
 
|-
 
|-
|0:10
+
|00:10
 
|Now I'll show you how to upload this file and move it to the uploaded folder here which is currently empty.
 
|Now I'll show you how to upload this file and move it to the uploaded folder here which is currently empty.
 
|-
 
|-
|0:18
+
|00:18
 
|If you recall, we're referring to a temporary area that is being stored on our web server.
 
|If you recall, we're referring to a temporary area that is being stored on our web server.
 
|-
 
|-
|0:25
+
|00:25
 
|Its not of much use right now.
 
|Its not of much use right now.
 
|-
 
|-
|0:29
+
|00:29
 
|We have all our properties here, so I'll say properties of the uploaded file so we know what we're doing.
 
|We have all our properties here, so I'll say properties of the uploaded file so we know what we're doing.
 
|-
 
|-
|0:34
+
|00:34
 
|We have all our specific properties here.
 
|We have all our specific properties here.
 
|-
 
|-
|0:38
+
|00:38
 
|I've given all of them easy to remember variable names so we don't need to comment each of these individually.
 
|I've given all of them easy to remember variable names so we don't need to comment each of these individually.
 
|-
 
|-
|0:46
+
|00:46
 
|First thing we will do is create an 'if' statement to check if there are any errors.
 
|First thing we will do is create an 'if' statement to check if there are any errors.
 
|-
 
|-
|0:53
+
|00:53
 
|Here if error code is bigger than zero meaning it has been issued by an error code then I'll say 'die'  
 
|Here if error code is bigger than zero meaning it has been issued by an error code then I'll say 'die'  
 
|-
 
|-
|1:03
+
|01:03
 
|And I will give an error message out "File couldn't..."  
 
|And I will give an error message out "File couldn't..."  
 
|-
 
|-
|1:11
+
|01:11
 
|Or 'Error uploading file, code error'.
 
|Or 'Error uploading file, code error'.
 
|-
 
|-
|1:20
+
|01:20
 
|This will give the user an error code.
 
|This will give the user an error code.
 
|-
 
|-
|1:23
+
|01:23
 
|Now the 'else' part.  
 
|Now the 'else' part.  
 
|-
 
|-
|1:25
+
|01:25
 
|I'll add these curly brackets to keep that simple and in a single line.
 
|I'll add these curly brackets to keep that simple and in a single line.
 
|-
 
|-
|1:29
+
|01:29
 
|So 'else' I want to use a function called 'move_uploaded_file'.
 
|So 'else' I want to use a function called 'move_uploaded_file'.
 
|-
 
|-
|1:39
+
|01:39
 
|Then we'll take the temporary name 'temp', which is the first parameter of this function and the second parameter is the destination which is 'uploaded folder'
 
|Then we'll take the temporary name 'temp', which is the first parameter of this function and the second parameter is the destination which is 'uploaded folder'
 
|-
 
|-
|1:51
+
|01:51
 
|So I'll type 'uploaded' and a forward slash.
 
|So I'll type 'uploaded' and a forward slash.
 
|-
 
|-
|1:59
+
|01:59
 
|And at the end of that we'll concatenate the name the file that we've uploaded.
 
|And at the end of that we'll concatenate the name the file that we've uploaded.
 
|-
 
|-
|2:07
+
|02:07
 
|So here it would just be 'name'.
 
|So here it would just be 'name'.
 
|-
 
|-
|2:10
+
|02:10
 
|This shows the user just adding the inter variables here.
 
|This shows the user just adding the inter variables here.
 
|-
 
|-
|2:15
+
|02:15
 
|Otherwise we would have to type these, for example - temp name.
 
|Otherwise we would have to type these, for example - temp name.
 
|-
 
|-
|2:19
+
|02:19
 
|Then go here and place it like this.
 
|Then go here and place it like this.
 
|-
 
|-
|2:22
+
|02:22
 
|It gets quite messy and hard to read.
 
|It gets quite messy and hard to read.
 
|-
 
|-
|2:25
+
|02:25
 
|So its easier to just keep these variables here.
 
|So its easier to just keep these variables here.
 
|-
 
|-
|2:33  
+
|02:33  
 
|Okay so now I'll get rid of these or rather I'll keep these.
 
|Okay so now I'll get rid of these or rather I'll keep these.
 
|-
 
|-
|2:37
+
|02:37
 
|And lastly echo out a message saying 'Upload complete'.
 
|And lastly echo out a message saying 'Upload complete'.
 
|-
 
|-
|2:41
+
|02:41
 
|Lets try this.
 
|Lets try this.
 
|-
 
|-
|2:47
+
|02:47
 
|I logon to our page and pick our file - 'intro to avi'.
 
|I logon to our page and pick our file - 'intro to avi'.
 
|-
 
|-
|2:51
+
|02:51
 
|I'll click on upload and we can see that upload is complete.  
 
|I'll click on upload and we can see that upload is complete.  
 
|-
 
|-
|2:55
+
|02:55
 
|Lets check my file.
 
|Lets check my file.
 
|-
 
|-
|2:57
+
|02:57
 
|Upload folder and click on my uploaded sub directory you can see that the file is here whereas before - it had been stored in the temporary directory on my web server.
 
|Upload folder and click on my uploaded sub directory you can see that the file is here whereas before - it had been stored in the temporary directory on my web server.
 
|-
 
|-
|3:08
+
|03:08
 
|So we've successfully uploaded our file here.
 
|So we've successfully uploaded our file here.
 
|-
 
|-
|3:13
+
|03:13
 
|There are a few more things that we need to do.
 
|There are a few more things that we need to do.
 
|-
 
|-
|3:15
+
|03:15
 
|Undo another 'if' statement or undo this 'if' statement.  
 
|Undo another 'if' statement or undo this 'if' statement.  
 
|-
 
|-
|3:20
+
|03:20
 
|We are going to check for specific file types that we don't want uploaded.
 
|We are going to check for specific file types that we don't want uploaded.
 
|-
 
|-
|3:24
+
|03:24
 
|So for example lets say I don't want avi files to be uploaded.
 
|So for example lets say I don't want avi files to be uploaded.
 
|-
 
|-
|3:30
+
|03:30
 
|What I could do here is say - if error is bigger than zero, don't upload files.  
 
|What I could do here is say - if error is bigger than zero, don't upload files.  
 
|-
 
|-
|3:37
+
|03:37
 
|Otherwise I'll start a new 'if'  statement inside the else
 
|Otherwise I'll start a new 'if'  statement inside the else
 
|-
 
|-
|3:41
+
|03:41
 
|And I'll create a block here.
 
|And I'll create a block here.
 
|-
 
|-
|3:47
+
|03:47
 
|And these are the conditions for the file.
 
|And these are the conditions for the file.
 
|-
 
|-
|3:51
+
|03:51
 
|I'll say - if the type of file - that's our type variable, t-y-p-e, 2 equal to signs, equals video dot avi.
 
|I'll say - if the type of file - that's our type variable, t-y-p-e, 2 equal to signs, equals video dot avi.
 
|-
 
|-
|4:09
+
|04:09
 
|As you saw in the first part of this, as I echoed it out, it was equal to video dot avi.  
 
|As you saw in the first part of this, as I echoed it out, it was equal to video dot avi.  
 
|-
 
|-
|4:19
+
|04:19
 
|And then we're saying that if it is equal to video dot avi then upload the file.
 
|And then we're saying that if it is equal to video dot avi then upload the file.
 
|-
 
|-
|4:28
+
|04:28
 
|I'll just move it down here and I will put that into the 'else' block.
 
|I'll just move it down here and I will put that into the 'else' block.
 
|-
 
|-
|4:32
+
|04:32
 
|So now I have - if the video is equal to avi then die and the message is 'That format is not allowed'.
 
|So now I have - if the video is equal to avi then die and the message is 'That format is not allowed'.
 
|-
 
|-
|4:44
+
|04:44
 
|Okay so now I'll delete this from our uploaded directory and I'll come back to my initial uploaded file.
 
|Okay so now I'll delete this from our uploaded directory and I'll come back to my initial uploaded file.
 
|-
 
|-
|4:54
+
|04:54
 
|I'll choose intro dot avi and when I click upload it says that that 'format is not allowed'
 
|I'll choose intro dot avi and when I click upload it says that that 'format is not allowed'
 
|-
 
|-
|5:01
+
|05:01
 
|And if you go to my uploaded directory you can see that the folder is empty.
 
|And if you go to my uploaded directory you can see that the folder is empty.
 
|-
 
|-
|5:06
+
|05:06
 
|Nothing has been uploaded.
 
|Nothing has been uploaded.
 
|-
 
|-
|5:08
+
|05:08
 
|Now instead of avi let us say I want to ban 'images with png' extension.
 
|Now instead of avi let us say I want to ban 'images with png' extension.
 
|-
 
|-
|5:15
+
|05:15
 
|I'll change it here and upload my file again.
 
|I'll change it here and upload my file again.
 
|-
 
|-
|5:23
+
|05:23
 
|You can see that because its an accepted file format, we get the message 'Upload complete' and its been transferred to my uploaded folder.
 
|You can see that because its an accepted file format, we get the message 'Upload complete' and its been transferred to my uploaded folder.
 
|-
 
|-
|5:33
+
|05:33
 
|Lets delete that again.  Oh! I canceled it.  Lets delete that again.
 
|Lets delete that again.  Oh! I canceled it.  Lets delete that again.
 
|-
 
|-
|5:42
+
|05:42
 
|Okay. So what we've seen here is how to specify a specific type.
 
|Okay. So what we've seen here is how to specify a specific type.
 
|-
 
|-
|5:47
+
|05:47
 
|What we also can do is specify a specific file size.
 
|What we also can do is specify a specific file size.
 
|-
 
|-
|5:51
+
|05:51
 
|I'll say 'or' using this 'or' operator and I'll say 'or' the size is bigger than half a megabyte.
 
|I'll say 'or' using this 'or' operator and I'll say 'or' the size is bigger than half a megabyte.
 
|-
 
|-
|6:04
+
|06:04
 
|This is half a megabyte, which is five hundred thousand bits sorry bytes.  I think I made a mistake and said bits instead of bytes.
 
|This is half a megabyte, which is five hundred thousand bits sorry bytes.  I think I made a mistake and said bits instead of bytes.
 
|-
 
|-
|6:14
+
|06:14
 
|So that's five hundred thousand bytes which is equal to 0 point 4 megabytes. I'll just say half a megabyte for now.
 
|So that's five hundred thousand bytes which is equal to 0 point 4 megabytes. I'll just say half a megabyte for now.
 
|-
 
|-
|6:29
+
|06:29
 
|This will evaluate the size and say is it bigger than half a megabyte.
 
|This will evaluate the size and say is it bigger than half a megabyte.
 
|-
 
|-
|6:38
+
|06:38
 
|Then it will say this format is not allowed.
 
|Then it will say this format is not allowed.
 
|-
 
|-
|6:43
+
|06:43
 
|So I'll change this message to accommodate 'Format not allowed or file size too big'.
 
|So I'll change this message to accommodate 'Format not allowed or file size too big'.
 
|-
 
|-
|6:56
+
|06:56
 
|So you can create an if statement for each of these that is for evaluating your type and evaluating your size.
 
|So you can create an if statement for each of these that is for evaluating your type and evaluating your size.
 
|-
 
|-
|7:03
+
|07:03
 
|You just need to take this condition and put it in another 'if' statement.
 
|You just need to take this condition and put it in another 'if' statement.
 
|-
 
|-
|7:09
+
|07:09
 
|So I go back here and I'll choose my file again.
 
|So I go back here and I'll choose my file again.
 
|-
 
|-
|7:12
+
|07:12
 
|Just making sure its there.
 
|Just making sure its there.
 
|-
 
|-
|7:14
+
|07:14
 
|Click upload and it'll say 'Format not allowed'.
 
|Click upload and it'll say 'Format not allowed'.
 
|-
 
|-
|7:19
+
|07:19
 
|Now if you go back to our code this is not in png format but it is exceeding the size limit.
 
|Now if you go back to our code this is not in png format but it is exceeding the size limit.
 
|-
 
|-
|7:25
+
|07:25
 
|Lets change this to 2 million which is 2 megabytes.
 
|Lets change this to 2 million which is 2 megabytes.
 
|-
 
|-
|7:31
+
|07:31
 
|Refresh and send that.
 
|Refresh and send that.
 
|-
 
|-
|7:33
+
|07:33
 
|We can see that our upload has been completed because this is only one megabyte in size.  
 
|We can see that our upload has been completed because this is only one megabyte in size.  
 
|-
 
|-
|7:39
+
|07:39
 
|That's all I have on File Upload for now.  
 
|That's all I have on File Upload for now.  
 
|-
 
|-
|7:44
+
|07:44
 
|This is all you need to know to use this to keep out specific file types and file sizes that are too large for your web server.
 
|This is all you need to know to use this to keep out specific file types and file sizes that are too large for your web server.
 
|-
 
|-
|7:54
+
|07:54
 
|If you don't want big files on your web server this is a good way to control it.
 
|If you don't want big files on your web server this is a good way to control it.
 
|-
 
|-
|7:58
+
|07:58
 
|Its very easy to create as you've seen.
 
|Its very easy to create as you've seen.
 
|-
 
|-
|8:01
+
|08:01
 
|Practice this and you'll be quite impressed with how useful this can be.
 
|Practice this and you'll be quite impressed with how useful this can be.
 
|-
 
|-
|8:05
+
|08:05
 
|If you've got any questions please don't hesitate to ask.
 
|If you've got any questions please don't hesitate to ask.
 
|-
 
|-
|8:08
+
|08:08
 
|Also please subscribe if you want to be notified on any updated videos or new videos.
 
|Also please subscribe if you want to be notified on any updated videos or new videos.
 
|-
 
|-
|8:15
+
|08:15
 
|Thanks for watching.  This is Joshua Mathew dubbing for the Spoken Tutorial Project. Bye.
 
|Thanks for watching.  This is Joshua Mathew dubbing for the Spoken Tutorial Project. Bye.

Revision as of 12:41, 10 July 2014

Time Narration
00:00 Welcome back. In the first part of this tutorial, I showed you how to take out specific properties of our uploaded file using this form here.
00:10 Now I'll show you how to upload this file and move it to the uploaded folder here which is currently empty.
00:18 If you recall, we're referring to a temporary area that is being stored on our web server.
00:25 Its not of much use right now.
00:29 We have all our properties here, so I'll say properties of the uploaded file so we know what we're doing.
00:34 We have all our specific properties here.
00:38 I've given all of them easy to remember variable names so we don't need to comment each of these individually.
00:46 First thing we will do is create an 'if' statement to check if there are any errors.
00:53 Here if error code is bigger than zero meaning it has been issued by an error code then I'll say 'die'
01:03 And I will give an error message out "File couldn't..."
01:11 Or 'Error uploading file, code error'.
01:20 This will give the user an error code.
01:23 Now the 'else' part.
01:25 I'll add these curly brackets to keep that simple and in a single line.
01:29 So 'else' I want to use a function called 'move_uploaded_file'.
01:39 Then we'll take the temporary name 'temp', which is the first parameter of this function and the second parameter is the destination which is 'uploaded folder'
01:51 So I'll type 'uploaded' and a forward slash.
01:59 And at the end of that we'll concatenate the name the file that we've uploaded.
02:07 So here it would just be 'name'.
02:10 This shows the user just adding the inter variables here.
02:15 Otherwise we would have to type these, for example - temp name.
02:19 Then go here and place it like this.
02:22 It gets quite messy and hard to read.
02:25 So its easier to just keep these variables here.
02:33 Okay so now I'll get rid of these or rather I'll keep these.
02:37 And lastly echo out a message saying 'Upload complete'.
02:41 Lets try this.
02:47 I logon to our page and pick our file - 'intro to avi'.
02:51 I'll click on upload and we can see that upload is complete.
02:55 Lets check my file.
02:57 Upload folder and click on my uploaded sub directory you can see that the file is here whereas before - it had been stored in the temporary directory on my web server.
03:08 So we've successfully uploaded our file here.
03:13 There are a few more things that we need to do.
03:15 Undo another 'if' statement or undo this 'if' statement.
03:20 We are going to check for specific file types that we don't want uploaded.
03:24 So for example lets say I don't want avi files to be uploaded.
03:30 What I could do here is say - if error is bigger than zero, don't upload files.
03:37 Otherwise I'll start a new 'if' statement inside the else
03:41 And I'll create a block here.
03:47 And these are the conditions for the file.
03:51 I'll say - if the type of file - that's our type variable, t-y-p-e, 2 equal to signs, equals video dot avi.
04:09 As you saw in the first part of this, as I echoed it out, it was equal to video dot avi.
04:19 And then we're saying that if it is equal to video dot avi then upload the file.
04:28 I'll just move it down here and I will put that into the 'else' block.
04:32 So now I have - if the video is equal to avi then die and the message is 'That format is not allowed'.
04:44 Okay so now I'll delete this from our uploaded directory and I'll come back to my initial uploaded file.
04:54 I'll choose intro dot avi and when I click upload it says that that 'format is not allowed'
05:01 And if you go to my uploaded directory you can see that the folder is empty.
05:06 Nothing has been uploaded.
05:08 Now instead of avi let us say I want to ban 'images with png' extension.
05:15 I'll change it here and upload my file again.
05:23 You can see that because its an accepted file format, we get the message 'Upload complete' and its been transferred to my uploaded folder.
05:33 Lets delete that again. Oh! I canceled it. Lets delete that again.
05:42 Okay. So what we've seen here is how to specify a specific type.
05:47 What we also can do is specify a specific file size.
05:51 I'll say 'or' using this 'or' operator and I'll say 'or' the size is bigger than half a megabyte.
06:04 This is half a megabyte, which is five hundred thousand bits sorry bytes. I think I made a mistake and said bits instead of bytes.
06:14 So that's five hundred thousand bytes which is equal to 0 point 4 megabytes. I'll just say half a megabyte for now.
06:29 This will evaluate the size and say is it bigger than half a megabyte.
06:38 Then it will say this format is not allowed.
06:43 So I'll change this message to accommodate 'Format not allowed or file size too big'.
06:56 So you can create an if statement for each of these that is for evaluating your type and evaluating your size.
07:03 You just need to take this condition and put it in another 'if' statement.
07:09 So I go back here and I'll choose my file again.
07:12 Just making sure its there.
07:14 Click upload and it'll say 'Format not allowed'.
07:19 Now if you go back to our code this is not in png format but it is exceeding the size limit.
07:25 Lets change this to 2 million which is 2 megabytes.
07:31 Refresh and send that.
07:33 We can see that our upload has been completed because this is only one megabyte in size.
07:39 That's all I have on File Upload for now.
07:44 This is all you need to know to use this to keep out specific file types and file sizes that are too large for your web server.
07:54 If you don't want big files on your web server this is a good way to control it.
07:58 Its very easy to create as you've seen.
08:01 Practice this and you'll be quite impressed with how useful this can be.
08:05 If you've got any questions please don't hesitate to ask.
08:08 Also please subscribe if you want to be notified on any updated videos or new videos.
08:15 Thanks for watching. This is Joshua Mathew dubbing for the Spoken Tutorial Project. Bye.

Contributors and Content Editors

Gaurav, Gyan, Pratik kamble, Sandhya.np14