I have changed the way of working with Uploads. I noticed when I select a folder to upload it selects all inner files even from sub-folders and in my main folder there are many sub folders and in every sub folder, there are are 2 to 3 files. File Names are as following.
6-AALIYAH WIGHTON - 299-SOLO-JAZZ-6 YEARS AND UNDER
7-ABIGAIL PALMER - 301-SOLO-LYRICAL-6 YEARS AND UNDER
4-ZOE CAMPBELL - 299-SOLO-JAZZ-6 YEARS AND UNDER.mp3
So, in file names the 2nd parameter is the folder name.
Like, in above 3 sample names, AALIYAH WIGHTON
, ABIGAIL PALMER
& ZOE CAMPBELL
are folder names. Which needs to be created first and then files will go inside these folders.
Here is the code.
if(isset($_POST['submit'])){
foreach ($_FILES['files']['name'] as $i => $name) {
if(strlen($_FILES['files']['name'][$i]) > 1) {
$Folder = explode('-', $name)[1];
$Path = 'BaberZamanTest/TEST/'.trim($Folder);
//First Make Directories or Folder if not exist
if(!file_exists($Path)){
mkdir($Path, 0777, true);
}
//If the Folder has no file $name in $Path then Move file
if(!file_exists($Path.'/'.$name)){
move_uploaded_file($_FILES['files']['tmp_name'][$i], $Path.'/'.$name);
}
}
}
}
<form method="post" enctype="multipart/form-data">
<input type="file" name="files[]" id="files" multiple webkitdirectory mozdirectory>
<input class="button" type="submit" name="submit" value="Upload" />
</form>
Now what is the issue.
Overall it is working perfect. But every time it skips first folder, Or some files in first folder.
When I select my folder it shows correct number of files. In folder there are 10
Sub folders and all sub folders have 22
total files in all. When I select, It shows correct number of files 22
but when upload process runs, it often uploads 20
files. Specially it misses the first folder only. all other folders work perfect. All files come there.
Kindly help me in this issue
I think you need to edit your php.ini
file first. Because the default number of max_file_uploads
is 20
and I am damn sure you have missed this part.
Go to you public_html
and locate php.ini
file. You can create a new php.ini
file if not exists, edit it with text editor and put there
max_file_uploads=50;
or what number of files you want.
It will work