Jump to content

Help with PHP/Javascript -> img class


jamiet757

Recommended Posts

I have a script that uploads images. It uses PHP to process the images and determine if there is an error or not. I have it set up so that $error= the error message, but if $error="", $result says "Successfully Uploaded"

 

Here is the problem:

When file is uploaded, either a success icon or a failed icon appear next to the message. Here is how it is currently set up:



    fileComplete: function(file, response) {

        this.options.processResponse || this

        var json = $H(JSON.decode(response, true));

        if (json.get('result') == 'success') {

            file.element.addClass('file-success');

            file.info.set('html', json.get('size'));

        } else {

            file.element.addClass('file-failed');

            file.info.set('html', json.get('error') || response);

        }

    },

I got rid of the JSON part on the PHP side, because it was too complicated and unnecessary for what I need it to do. I am not very familiar with javascript, but I want it to give the class of either "file-failed" or "file-success" depending on what $error is. If $error is nothing, it needs to add the class "file-success", otherwise it needs to add "file-failed".

 

Does this make sense to anyone? I hope so.

Link to comment
https://forums.phpfreaks.com/topic/196064-help-with-phpjavascript-img-class/
Share on other sites

If you're just trying to style something differently depending on the outcome of your PHP, what's the JS for?

 

<span class="<? if(empty($error)) { echo "file-success"; } else { echo "file-failed"; } ?>">

 

Sorry if I'm missing the point.

 

It is javascript because you can select multiple files to upload, and it updates the progress of each file in the list, so with PHP it would just update after it is completely finished, not on-the-fly

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.