Welcome Guest, Not a member yet? Register   Sign In
Upload Error Response
#1

[eluser]jroot[/eluser]
Hello all

I built a method that handles uploads... Real standard. Set config params and then call the upload library with the config params.

The upload method is called from another method that prepares various inputs for the upload. This upload method may get called several times for many files. Everything works fine with one exception.

In the case that there are multiple file uploads and multiple file upload errors, the errors are concatenated for every upload error. For example, let's say that file 1 is too big and file 2 is the wrong type.

The error for file 1 is 'too big.'.
The error for file 2 is 'too big.wrong type'. The errors are concatenated.

In display_errors() of upload.php, the offender is this line (862):
$str .= $open.$val.$close;

Of course, killing the concat operator (.) after $str solves my problem. But in testing, I found that multiple errors on one file are not returned anyway. It returns the first error encountered on the file... and that's it. In reviewing this I thought that the loop and concat was setup to catch multiple errors on one file. But that isn't so.

My Questions:
1) What is the reason for the concat operator in the foreach loop if
display_errors() will return only a single error per file upload? I just want to know if I'm breaking anything by killing the (.).
2) How is upload.php storing the errors across different calls to do_upload()?

Thanks all!
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

The foreach loop in the display_errors() method simply wraps the supplied opening tag (default <p>) and the specified closing tag (default </p>) around each error. You can change them by supplying a different opening and closing tag when you call display_errors().

As far as I can see, do_upload() should only really be called once in any given HTTP request.
#3

[eluser]jroot[/eluser]
[quote author="TheFuzzy0ne" date="1241755370"]As far as I can see, do_upload() should only really be called once in any given HTTP request.[/quote]

Fuzz,

Thanks for the reply and the welcome! I appreciate it.

That's what I guessed as I reviewed the library. The messages are stored and made available via display_errors(). Thanks for the tag concat info... I didn't catch that because it seemed handled in one iteration.

Code:
function display_errors($open = '<p>', $close = '</p>')
    {
        $str = '';
        foreach ($this->error_msg as $val)
        {
            $str .= $open.$val.$close;
        }
    
        return $str;
    }

Notice that open calls the open tag, and close calls the closing tag in a single iteration. By just looking at the library I can't identify the instance where the error would be an array greater than 1 item. If all that is thrown is a single error in the error array, the iteration is unneccesary.

You are probably correct that 1 upload request per http request is how the library was designed. That's probably why people have been posting issues with multiple uploads - and requesting a true multi-upload library. However, it does seem to work with two modifications. First, I strip the tags in the response anyway because my view handles the display. Second, by pulling the concat operator, the errors are not concatenated.

If I could identify the instance where the error returned would be multiple errors, I could understand the potential risk of removing the concat operator...
#4

[eluser]jroot[/eluser]
[quote author="jroot" date="1241797096"][quote author="TheFuzzy0ne" date="1241755370"]As far as I can see, do_upload() should only really be called once in any given HTTP request.[/quote]

If I could identify the instance where the error returned would be multiple errors, I could understand the potential risk of removing the concat operator...[/quote]

Sorry for leaving this thread hanging... I figured out what I was doing wrong. I wasn't re initializing the upload everytime with the new parameters. I was simply loading the library with data...

That means that you can do multiple uploads without a problem. You just need to reinitialize it everytime to input the new data. This will also clear all of the errors.
#5

[eluser]TheFuzzy0ne[/eluser]
Thanks for reporting back. I'm really sorry I hadn't replied. I'd completely forgotten about this thread... Glad you got it sorted. Smile




Theme © iAndrew 2016 - Forum software by © MyBB