Jump to content

files in directory


dreamwest

Recommended Posts

OK all the examples work but im trying to integrate it with my script - im lost.

 

Heres what ive got at the moment:

// connect to source ftp server
$source_conn = ftp_connect($source_ftp_server) or die("Could not connect to $source_ftp_server!");
ftp_login($source_conn, $source_ftp_user, $source_ftp_pass) or die("Could not login to $source_ftp_server!");

// get a list of all files and pick a random one
$source_file_list = ftp_nlist($source_conn, ".");

do {
shuffle($source_file_list);
$our_file = $source_file_list[0];
} while (strtolower(substr($our_file, -4)) != '.jpg');

// get that file
ftp_get($source_conn, "tmp-" . $our_file, $our_file, FTP_BINARY) or die("Could not download $our_file from $source_ftp_server!");

Link to comment
https://forums.phpfreaks.com/topic/161936-files-in-directory/#findComment-854744
Share on other sites

OK ive manged to recreate 20,000 images but the script times out, i have over 100,000 images in this directory

 

is there a way i can only select files that are over 8kb in size, i tried this but its only selecting images 3000.jpg instead of 1_3000.jpg

 


$dir = '/home/user/public_html/thumb/';
foreach(scandir($dir) as $file){
$filesize = round(filesize($file)/1024);
  if(!preg_match('/^\d+_/',$file) && $filesize >  continue; //Skip anything that doesn't start with a #_
  echo "$file<br>";

Link to comment
https://forums.phpfreaks.com/topic/161936-files-in-directory/#findComment-854849
Share on other sites

$dir = '/home/user/public_html/thumb/';
$files = glob($dir . '?_*.jpg');
foreach($files as $file){
  if( (round(filesize($file)/1024) ) > 8 ) {
    //do things with this file
  }
}

This is assuming that the glob correctly selects the files you intend, and your rounding is correct.  Haven't tested.  You may have to modify the glob function to accommodate capitalization of file extensions.  See the manual for more info.

Link to comment
https://forums.phpfreaks.com/topic/161936-files-in-directory/#findComment-854868
Share on other sites

$dir = '/home/user/public_html/thumb/';
$files = glob($dir . '?_*.jpg');
foreach($files as $file){
  if( (round(filesize($file)/1024) ) > 8 ) {
    //do things with this file
  }
}

This is assuming that the glob correctly selects the files you intend, and your rounding is correct.  Haven't tested.  You may have to modify the glob function to accommodate capitalization of file extensions.  See the manual for more info.

 

Thanks for the help. Ive figured it out, and successfully make new -smaller thumbs in the directory.

But i have one final step, i need to set it to cron and run it once a day but limit the files it selects to something like 30 files, or a time range like select files modifided today only

 

require_once('../include/SimpleImage.class.php');

$dir = '/home/user/public_html/thumb/';
foreach(scandir($dir) as $file){

  if(!preg_match('/^\d+_/',$file)) continue; //Skip anything that doesn't start with a #_

$filesize = round(filesize($dir."".$file)/1024);
if ($filesize > 6){
echo "<hr>".$file." Image has size of ".$filesize." - NOW RESIZING <hr>";
// resize
$image = new SimpleImage();
$image->load($dir."".$file);
$image->resize(140,110);
$image->save($dir."".$file);
}else{
echo "".$file." SKIPPING image has size of ".$filesize."<br>";
}

}

Link to comment
https://forums.phpfreaks.com/topic/161936-files-in-directory/#findComment-854878
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.