Note that there are some explanatory texts on larger screens.

plurals
  1. POManaging php sessions on multiple file uploads
    primarykey
    data
    text
    <p>I'm working in a multiple image upload social web app. I'm assigning a <code>$_session['file_id']</code> to each uploaded file as an array index (file id comes from db). But I only want users to upload a maximum of 4 images per post. So I'm counting the <code>images.length</code> before upload, and if it's <code>== 4</code>, alerting the user he can't upload more files at the same time, else, the normal upload happens. For security purposes I have an <code>unset($_session['file_id'])</code> for making sure the 4 files won't be uploaded on errors, or user changes on javascript (a <code>for</code> loop on every upload, to count <code>$_session['file_id'])</code>. The problem I'm having is that the js itself ain't enought to make sure the file ain't uploaded 4 times, I guess ajax upload stay on queue, and check for file number before the 4th file is uploaded. Is there any other approach I can use direct on php, remembering I can't unset files for common users (4 files are already upload and waiting for send button), but I need plus to unset files if user reflesh, or quit the page? Thank your for your time.</p> <p><strong>JavaScript</strong></p> <pre><code>var checkfilecount = 0; $('#file').change(function() { checkfilecount++; checkfile = $("#images).length; if (checkfile &lt; 4 &amp;&amp; checkfilecount &lt; 4) { $("#filesend").submit(); } else { setTimeout(function(){ alert("Sorry, You can`t upload too many files at once") },3000) } }) </code></pre> <p>and on #postsend:</p> <pre><code>checkfilecount = 0; </code></pre> <p><strong>PHP</strong></p> <pre><code>if (isset($_SESSION['files_id'])) { $counting = 0; foreach($_SESSION['files_id'] as $key =&gt; $val) { $counting++; if ($counting == 4) { unset($_SESSION['files_id']); exit("error on session array"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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