Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that you are outputting the name of the uploaded file when the PHP code renders the page, which is before the (next) image is uploaded.</p> <p>This happens on this line in the <code>stopImageUpload()</code> JavaScript function:</p> <pre><code>imageNameArray = &lt;?php echo $output ?&gt;; </code></pre> <p>There are a couple ways you can resolve this, but I would go for the straightforward way of passing the file name back via the <code>stopImageUpload()</code> function.</p> <pre><code>// stolen from http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding function htmlEncode(value) { return $('&lt;div/&gt;').text(value).html(); } function stopImageUpload(success, filename) { var imageNameArray = new Array(); var result = ''; if (success) { result = '&lt;span class="msg"&gt;The file was uploaded successfully!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;'; $('.listImage').append(htmlEncode(filename) + '&lt;br/&gt;'); } else { result = '&lt;span class="emsg"&gt;There was an error during file upload!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;'; } } </code></pre> <p>Then you simply need to adjust the last line of <code>imageupload.php</code>:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt;window.top.stopImageUpload(&lt;?php echo $result ? 'true' : 'false'; ?&gt;, '&lt;?php echo $_FILES['fileImage']['name'] ?&gt;');&lt;/script&gt; </code></pre> <p><em>Note: If you have the option turned on to allow <code>&lt;?= ?&gt;</code> blocks you can make the above code look much nicer:</em></p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt;window.top.stopImageUpload(&lt;?= $result ? 'true' : 'false'; ?&gt;, &lt;?= $_FILES['fileImage']['name'] ?&gt;);&lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload