2012-10-26 59 views
0

我正在嘗試生成一個SQL命令列表,我稍後會插入它。在這個時候,我似乎被困在唯一的部分是循環文件名。我需要我的scandir循環訪問nofilter目錄,並在每次給出新行或sql查詢時更改$ image。我有下面的代碼和輸出。基本上沒有SQL查詢應具有相同的$圖像被回顯到它PHP通過scandir循環輸出不同的文件名

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>"; 

} 

輸出看起來像這樣

The number is 1351314000 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351314000', NULL , '1351314000', '100000103637895'); 

The number is 1351328400 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351328400', NULL , '1351328400', '100000103637895'); 

The number is 1351342800 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351342800', NULL , '1351342800', '100000103637895'); 

The number is 1351357200 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351357200', NULL , '1351357200', '100000103637895'); 

The number is 1351371600 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351371600', NULL , '1351371600', '100000103637895'); 

The number is 1351386000 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351386000', NULL , '1351386000', '100000103637895'); 

The number is 1351400400 8120925654_4041b7c50f_o.jpg 


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/8120925654_4041b7c50f_o.jpg', NULL , NULL , NULL , '0', '135031429962113', 'AAAGLZAMh7YSUBALRMCW60Rdol1kD80ZBNymqkgyQfBXDour2KsvVWKFcnZB9cU9OSLRMQjnEuKHZCTNoTZC4jf9GFtMU11BTD8JZAUFl0EVgZDZD', 'page', 'photo', 'schedule', '0', '1351400400', NULL , '1351400400', '100000103637895');
+1

就是這一切,還是你有更多? – JvdBerg

+0

這是什麼迴路? 'for($ i = 1351314000; $ i <= 1351400400; $ i + = 14400){' –

+0

@AnthonyHatzopoulos這些是UNIX時間戳。 – Kermit

回答

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>"; 

} 
+0

這看起來工作完美!非常感謝。 –

+0

很好,如果你喜歡stackoverflow上的答案,它通常接受他們或upvote答案 –

+0

更好地刪除'.'和'..'文件,您可以使用'$ files = array_diff(scandir($ dir),array( ')','。'));' –

0

你混淆了你的括號:

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

} 

我開始格式化你的代碼,一旦它被格式化,你可以看到你的一個循環沒有做任何事情。如果你對代碼進行格式化,那麼看到這些東西就更容易了。

你的外部循環使用$images變量,然後有一個內部循環(見上文),它除了定義$image變量之外什麼也不做,然後你得到意想不到的結果,因爲你在使用這個變量。

+0

我有同樣的觀點。同意! –

相關問題