2

I'm currently working on a photoalbum thing on my website and was wondering is there is a way to upload files separately even though I selected multiple files for upload, let me explain:

<form method="post" action="upload.php" enctype="multipart/form-data">
    <input name='uploads[]' type="file" accept="image/*" multiple>
    <input type="submit" value="Send">
</form>

<?php
$y=count($_FILES['uploads']);
for($x=0;$x<$y;$x++) {
    echo $_FILES['uploads']['name'][$x];
    echo "<br>";  
}
?>

So I've got these simple lines of code. And basically (As you can see) you can upload multiple files. But let's say that that my 'upload_max_filesize' is at 8M. I can only select 4 images of 2MB each to upload successfully, otherwise I overwrite the max upload size. My question is, is there a PHP way to keep the form structure the same but let the script handle one file at the time so I can upload 5.000 files from 5MB's each for example?

5
  • 2
    no. php cannot do anything about how the client uploads files. if the user selects to upload 500 files of 500gigs total, PHP will barf, but you can't do anything about that, because the barfing occurs BEFORE your code will ever execute. Your code will not execute until AFTER the upload has completed (succesfully or not). Commented Sep 5, 2014 at 17:54
  • 1
    You could upload them one-by-one using AJAX … Commented Sep 5, 2014 at 17:54
  • @MarcB I realised that but thought there maybe was a creative way with array's before uploading, but thanks for clearing that up! Commented Sep 5, 2014 at 17:58
  • @CBroe Do you maybe have an example? Commented Sep 5, 2014 at 18:01
  • 1
    you could set the max_file_uploads=1 in the php.ini file and then provide an error message when the user tries more than 1, as@CBroe says you can handle asynchronous uploading with ajax see stackoverflow.com/questions/6831883/upload-file-with-jquery/… Commented Sep 5, 2014 at 18:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.