Updated 056 How to use the file field type to upload a file in JCB (markdown)

Amigo 2019-09-10 09:11:11 +02:00
parent 60410e389a
commit 0b4ffe98b1
1 changed files with 1 additions and 2 deletions

@ -79,10 +79,9 @@ 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.<<<<<<<<<<
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). <<<<<<<<<<
We will take some stuff away and add our own little messages, so we do not depend on the INSTALLER MSG. We'll just copy this whole function(see video) all the way up there, control copy it, go to look, our class and I'm going to paste it in here above. So there are some key things I would like to change here for example. [00:18:23](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m23s) I'm thinking let's change the function name and we call it 'myUploadFunction' for now. We going to pass it the input. We don't 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 don't want to have it 'raw', because it's an image. We want this to be 'array' that we can check the values. This looks fine. We can say here [00:19:19](https://www.youtube.com/watch?v=o482sK4DxkM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m19s) set 'uploads are not enabled in php', that seems fine. 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 really want to make sure that it happens. We don't need the zlib because we are not going to unzip anything. We could remove this part(see video).
### Checking If Userfile Is An Array