1084

The Submit Upload Method

Comments for “The Submit Upload Method”
 

Posted by perkin524 on Sunday 28th January 2024 at 19:50 GMT

This the title of a helpful doc in 'Working with Images' but it only refers to image uploading whereas I want to submit a form (for a blog) with both text input and an image. I have managed to produce a method to handle this except that I got into a muddle dealing with validation using the $_POST and the $_FILES arrays.
$validation_str = 'allowed_types[gif,jpg,jpeg,png]|max_size['.$max_file_size.']|max_width['.$max_width.']|max_height['.$max_height.']';
    $this->validation_helper->set_rules('picture', 'item picture', $validation_str);
$result = $this->validation_helper->run();

I can vardump the $validation_str OK but when I echo the run() result - which is a boolean - it just sends me to the base url.
It seems that I have the wrong element for 'picture'. I have tried using the image temp path and the image name without success.
Can anyone give me a steer?

perkin524

User Level: Guest

Date Joined: 7/07/2021

Posted by djnordeen on Sunday 28th January 2024 at 20:14 GMT

Hello,
The reason for this is because they are seperate.
Form submit
Then upload image.
Dan
Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by perkin524 on Sunday 28th January 2024 at 20:56 GMT

So what you are saying is that a form combining image and text inputs is absolutely not possible? And if so, what is the value of the 'picture' element in the validation helper rule?

This comment was edited by perkin524 on Sunday 28th January 2024 at 21:06 GMT

perkin524

User Level: Guest

Date Joined: 7/07/2021

Posted by djnordeen on Sunday 28th January 2024 at 21:14 GMT

Hello,
What I am saying is the way images are uploaded.
Most anything is possible.
You just have to figure out how to do both in your submit.

You could post your controller submit method and your form view file.
And we can go from there.
Dan
Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by perkin524 on Sunday 28th January 2024 at 22:03 GMT

Many thanks Dan for responding. Actually I have now got it working - possibly rather clumsily but hey...
Here is my image validation method:
function _image_validation($data)
    {
        $blogimgtemp = $data['blog_image']['tmp_name'];
        $image_size = $data['blog_image']['size'];
        $blogimgname = $data['blog_image']['name'];
        $image_info = getimagesize($blogimgtemp);
        $image_width = $image_info[0];
        $image_height = $image_info[1];
        if ($image_size > 150000 || $image_width > 1000 || $image_height > 1000) {
            $val = 0;
        } else {
            $val = 1;
        }
        return $val;
    }

I'm sure there is a more pro way of doing it.

perkin524

User Level: Guest

Date Joined: 7/07/2021

×