Welcome Guest, Not a member yet? Register   Sign In
Upload files with session (probably)
#1

[eluser]sojic[/eluser]
Here is scenario:

Product form (product name, price, category... and images). After submit, browser send fields and images... form verification class verifying the data and show same form (with error messages). Images are already uploaded. User correct the errors (fill forgotten required field) and submitting the form again (this time without images, because the images are uploaded with first submitting).

How to handle this?
#2

[eluser]sojic[/eluser]
Anybody to give me a hit?
#3

[eluser]pistolPete[/eluser]
I can think of two different implementations:

1) AJAX based:

Validate the input fields using AJAX, let the user only submit the form if all fields are valid =>files are uploaded only once

2) "Cache" the uploaded files:

Upload the files, validate the input fields. If there are validations errors, save the filenames of the uploaded files either into a database table or the session user data; you could also use a hidden input field.
If validation is passed, fetch the filenames again.
Problem: You need to implement a garbage collection, if a user does upload files but does not complete the form; you could extend the session library, which already has a garbage collection, and let it delete those unused files.
#4

[eluser]sojic[/eluser]
So... $this->upload->data() return successful uploaded images
Code:
Array
(
    [file_name] => Array
        (
            [0] => news_keys5.jpg
        )

    [file_size] => Array
        (
            [0] => 33.05
        )

    [file_type] => Array
        (
            [0] => image/jpeg
        )

    [file_ext] => Array
        (
            [0] => .jpg
        )

    [orig_name] => Array
        (
            [0] => news_keys.jpg
        )

    [image_width] => Array
        (
            [0] => 437
        )

    [image_height] => Array
        (
            [0] => 290
        )

    [image_type] => Array
        (
            [0] => jpeg
        )

    [image_size_str] => Array
        (
            [0] => width="437" height="290"
        )

    [file_path] => Array
        (
            [0] => /home/osogovo/domains/php.mk/public_html/genel/public/images/products/temp/
        )

    [full_path] => Array
        (
            [0] => /home/osogovo/domains/php.mk/public_html/genel/public/images/products/temp/news_keys5.jpg
        )

    [raw_name] => Array
        (
            [0] => news_keys5
        )

    [is_image] => Array
        (
            [0] => 1
        )

)

This result is saved into session data. After next upload, I want to merge new uploaded image data with this one (from session).

Any hints??? I try array_push, array_merge_recursive, but it was unsuccessful.




Theme © iAndrew 2016 - Forum software by © MyBB