Tell me, who knows how to find a file in Amazon S3 using the API for PHP . There is a certain structure with subdirectories; according to the API documentation itself, you can get a list of directory files using the Prefix parameter as the directory path. But is it possible already within the framework of the directory to search by name pattern, for example file-?-name , where is the question mark like any character? And the same question about searching folders, for example catalog/image/?/main , what does it mean to select a list of files from all the subdirectories of the image directory and in each subdirectory to get a list of files from the main directory?

UPD: There is a request to give the code, in principle there is the code for working with the API as it is

 $bucket = 'aws_bucket'; $s3 = new Aws\S3\S3Client(array( 'region' => 'aws_region', 'credentials' => [ 'key' => 'aws_key', 'secret' => 'aws_secret', ] )); $file_list = $s3->listObjects(array( 'Bucket' => $bucket, 'Prefix' => 'uploads/images/100-', )); 

This is how the documentation returns a list of files from the / images directory where the name starts with "100-", but for example you need to get a list of files using the mask "100 -? - foro.jpg" so that the list contains files with the name: "100- quality-foto.jpg, 100-quality1-foro.jpg "but did not get files named" 100-quality-foto1.jpg "or" 100-quality-foto.png ", i.e. files with a different right side of the name or another extension. As far as I understand privately, you can use Suffix together with Prefix in which you can define the end of the line, but this does not solve the problem of searching in several directories or using a complex file mask like "100 -? - foto.?".

  • Give a sample code and then you will try to help. - Pollux
  • array_filter($file_list, $item => preg_match($item, $pattern)); - etki
  • @Etki An interesting way, I didn’t think from this side, means working with an array of files already received from the server, if you don’t find a way to resolve the issue with collecting the desired list right from the recycle bin, you will have to use this option. This method has one drawback, based on the API limitations in the response there can be no more than 1000 entries (files), in principle, while a large number of files are not used, but in the future everything can be. - Mihalichman

0