Updated 056 How to use the file field type to upload a file in JCB (markdown)
parent
0b4ffe98b1
commit
4d6b40fa12
@ -79,15 +79,16 @@ And now we can take the next step to actually check this array exists. There is
|
||||
|
||||
[00:16:58](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m58s)
|
||||
|
||||
Let's copy the function and adapt it to our needs and just put it into our class. In components go to the `installer`, then, `model`, and then on `install`, and scroll down till you see one that says '`getPackageFromUpload`'. [00:17:29](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m29s) This is the function which is really ideal for the task. It takes care of a lot of sanitizing, it has a lot of error checks in it, and it should be useful for us in this case. We will take some stuff away and add our own short messages, so we do not have to depend on the `INSTALLER MSG`. Just copy this whole function(see video). So there are some key things I would like to change, for example, [00:18:23](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m23s) change the function name and call it '`myUploadFunction`' for now. We pass to it the input and do not want that to be done twice. [00:18:50](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m50s) We know this is going to be '`jform`', and we definitely do not want to have it '`raw`', because it is an image. We want this to be an '`array`' that we can check the values. [00:19:19](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m19s) We can say here set '`uploads are not enabled in php`'. We can take these messages and put them in here, because JCB is going to grab this once we put it into our component, and going to add it to our language files for our component, this is to make sure that it happens. We do not need the `zlib` because nothing is going to be unzipped. This part can be removed.(see video). <<<<<<<<<<
|
||||
|
||||
|
||||
Let's copy the function and adapt it to our needs and just put it into our class. In components go to the `installer`, then, `model`, and then on `install`, and scroll down till you see one that says '`getPackageFromUpload`'. [00:17:29](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m29s) This is the function which is really ideal for the task. It takes care of a lot of sanitizing, it has a lot of error checks in it, and it should be useful for us in this case. We will take some stuff away and add our own short messages, so we do not have to depend on the `INSTALLER MSG`. Just copy this whole function(see video). So there are some key things I would like to change, for example, [00:18:23](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m23s) change the function name and call it '`myUploadFunction`' for now. We pass to it the input and do not want that to be done twice. [00:18:50](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m50s) We know this is going to be '`jform`', and we definitely do not want to have it '`raw`', because it is an image. We want this to be an '`array`' that we can check the values. [00:19:19](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m19s) We can say here set '`uploads are not enabled in php`'. We can take these messages and put them in here, because JCB is going to grab this once we put it into our component, and going to add it to our language files for our component, this is to make sure that it happens. We do not need the `zlib` because nothing is going to be unzipped. This part can be removed.(see video).
|
||||
|
||||
### Checking If Userfile Is An Array
|
||||
|
||||
[00:19:58](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m58s)
|
||||
|
||||
There is going to be a check where we've got a file set of files here. It's got a check wither that userfile is an array. If it's not, it want to say no file was selected or no file was uploaded. We can just type that in. If at this point we detect any errors, we basically want to erase those errors and break out of this upload. So let's see UPLOADERROR, WARNINGUPLOADERROR. I suppose we need to go look at these language strings in the language file of the installer to correctly translate these. I'm not going to do that, so I'm just going to say error. [00:20:59](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m59s) You can do that on your own.
|
||||
It is going to check if we got a set of files here. It is going to check if that `($userfile)` is an `!is_array`. If it is not, it want to say no file was selected or no file was uploaded. We can just type that in. If at this point we detect any errors, we basically want to erase those errors and break out of this upload. So let's see `UPLOADERROR`, `WARNINGUPLOADERROR`. I suppose we need to go look at these language strings in the language file of the installer to correctly translate these but I am not going to do that but just going to say `error`. <<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
### Checking The Upload Size
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user