0

我正在尝试生成稍后将插入的 SQL 命令列表。此时我似乎被困住的唯一部分是循环文件名。我需要我的 scandir 循环遍历 nofilter 目录并在每次给出新行或 sql 查询时更改 $image。我有下面的代码和输出。基本上没有 sql 查询应该有相同的 $image 被回显到其中

for ($i=1351314000; $i<=1351400400; $i+= 14400) {
    $images = scandir("/home/fb/public_html/post/uploads/nofilter/");
    foreach($images as $image) {

    }

//copy file over from no filter
$orig = "/home/fb/public_html/post/uploads/nofilter/".$image."";
$dest =   "/home/fb/public_html/post/uploads/".$image."";
//copy($orig, $dest);


//output
  echo "The number is " . $i . "<br />";
echo $image;
echo "<br>";
echo "<br>";
echo "<br>";

echo "

INSERT INTO `fb_fb`.`postcron_schedule` (
`id` ,
`status_message` ,
`link` ,
`photo_url` ,
`status_name` ,
`status_caption` ,
`status_description` ,
`uid` ,
`page_id` ,
`access_token` ,
`post_to` ,
`status_type` ,
`schedule_type` ,
`is_process` ,
`process_time` ,
`process_at` ,
`display_time` ,
`created_by`
)
VALUES (
NULL , '', '', '/home/fb/public_html/post/includes/../uploads/". $image ."', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '". $i ."', NULL , '". $i ."', '100000103637895'
);
";

echo "<br>";
echo "<br>";

 }

输出看起来像这样

号码是1351314000 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351314000 ', NULL , '1351314000', '100000103637895' );

号码是1351328400 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351328400 ', NULL , '1351328400', '100000103637895' );

号码是1351342800 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351342800 ', NULL , '1351342800', '100000103637895' );

号码是1351357200 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351357200 ', NULL , '1351357200', '100000103637895' );

号码是1351371600 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351371600 ', NULL , '1351371600', '100000103637895' );

号码是1351386000 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351386000 ', NULL , '1351386000', '100000103637895' );

号码是1351400400 8120925654_4041b7c50f_o.jpg


插入`fb_fb`.`postcron_schedule`(`id`,`status_message`,`link`,`photo_url`,`status_name`,`status_caption`,`status_description`,`uid`,`page_id`,`access_token`, `post_to`,`status_type`,`schedule_type`,`is_process`,`process_time`,`process_at`,`display_time`,`created_by`)值(NULL,'','','/home/fb/public_html/交/包括/../上传/ 8120925654_4041b7c50f_o.jpg 'NULL,NULL,NULL, '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', '页', '照片', '日程', '0',' 1351400400 ', 空值, '1351400400', '100000103637895');
4

2 回答 2

0

你把牙套弄混了:

// does nothing
for( $images as $image ) {

}

我开始格式化你的代码,一旦它被格式化,你可以看到你的一个循环没有做任何事情。如果您格式化代码,那么更容易看到这些东西。

您的外部循环使用该$images变量,然后有一个内部循环(见上文)除了定义该变量之外什么都不做$image,然后您会得到意想不到的结果,因为您正在使用该变量。

于 2012-10-26T13:43:37.597 回答
0

根据您的评论,为什么不这样做呢?

<php
$time = time();
$images = scandir("/home/fb/public_html/post/uploads/nofilter/");
foreach($images as $image) {
    if ($image == '.' || $image == '..') {
        continue;
    }

    $time += 14400; //add 4 hours every interval

    //copy file over from no filter
    $orig = "/home/fb/public_html/post/uploads/nofilter/".$image."";
    $dest =   "/home/fb/public_html/post/uploads/".$image."";
    //copy($orig, $dest);


    //output
      echo "The number is " . $time . "<br />";
    echo $image;
    echo "<br>";
    echo "<br>";
    echo "<br>";

    echo "

    INSERT INTO `fb_fb`.`postcron_schedule` (
    `id` ,
    `status_message` ,
    `link` ,
    `photo_url` ,
    `status_name` ,
    `status_caption` ,
    `status_description` ,
    `uid` ,
    `page_id` ,
    `access_token` ,
    `post_to` ,
    `status_type` ,
    `schedule_type` ,
    `is_process` ,
    `process_time` ,
    `process_at` ,
    `display_time` ,
    `created_by`
    )
    VALUES (
    NULL , '', '', '/home/fb/public_html/post/includes/../uploads/". $image ."', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '". $time ."', NULL , '". $time ."', '100000103637895'
    );
    ";

    echo "<br>";
    echo "<br>";

 }
于 2012-10-26T13:52:36.300 回答