【问题标题】:Pagination in FOREACH loop with OBJECTS from WPS APK使用 WPS APK 中的 OBJECTS 在 FOREACH 循环中进行分页
【发布时间】:2018-02-15 20:43:05
【问题描述】:

我编写的这段代码运行良好,它从 s3 存储桶中的嵌套文件夹中检索文件,这些文件在登录用户更改时会发生变化,使用根文件夹在嵌套文件夹中提供来自 jpg 的图像以创建 DIV,并打印出获取的信息从与图像存储在同一文件夹中的 CSV 文件中。

$current_user = wp_get_current_user();  
$current_user_nambre = $current_user->user_login;
$dir = 's3://xy/zvx/users/' . $current_user_nambre . '/';

$s3 = new S3Client([
    'region' => 'eu-central-1',
    'profile' => 'default',
    'version' => '1'
]);

$s3->registerStreamWrapper();
$products = new RecursiveDirectoryIterator($dir);
$medias = new RecursiveDirectoryIterator($is_product);
                    foreach ($medias as $is_thumb) 
                    {[...]

它有效,而且完美。但是...如果它发现太多 CSV,FirstByte 花费的时间太长,服务器会自动退出请求,给用户一个超时页面。

我想做的是在FOREACH 中使用分页,但它指出我不能将array_slice 用于对象...

【问题讨论】:

    标签: php foreach aws-sdk aws-php-sdk


    【解决方案1】:

    我使用LimitIterator 管理它,它运行良好。

    $products = new RecursiveDirectoryIterator($dir);
    $limitIterator = new LimitIterator($products, $offset, $limit);
    $n = 0;
    foreach ($limitIterator as $is_product) {
    [...]
    
    
    [...] }
    if ($n == 10) {
        echo '<a href="?offset='.($offset + 10).'">Next</a>';
    

    在stackoverflow上看到here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-13
      • 2018-09-17
      • 2015-03-28
      • 2012-08-06
      • 2019-07-12
      • 2013-04-10
      • 2020-06-17
      • 2020-07-18
      相关资源
      最近更新 更多