TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   mass import of jpeg (http://www.talkphp.com/absolute-beginners/3572-mass-import-jpeg.html)

Lou_Gato 11-07-2008 03:27 AM

mass import of jpeg
 
lets say i have a directory where all jpgs were uploaded to.. how would i do a mass import into the database.? I am really stumped on this one..help would be much appreciated.
thanks

awuehr 11-07-2008 08:11 AM

Hint: PHP: readdir - Manual and PHP: glob - Manual

Greetings,

Alex

Runar 11-07-2008 10:09 AM

I made a simple example. It will return all visible files (hides files starting with .), including folders. If you want to confirm that the file in fact is an image before doing anything with the result, then you will have to modify it yourself, or let me know.

PHP Code:

<?php

// Turn on error reporting
ini_set'display_errors''yes' );

// Set path to our directory (for easier use)
// Remember the last slash (/)!
$directory_path 'your/image/folder/';

// Open the directory
$directory opendir$directory_path );

// Read the directory content
while( ( $file readdir$directory ) ) !== false )
{
    
// Drop hidden files and files which names begins with a dot
    
if( substr$file0) != '.' )
    {
        
// Put data in variables
        
$filename $file;
        
$filesize filesize$directory_path $file );
        
        
// Do your database magic here
    
}
}
    
?>


Tanax 11-07-2008 10:38 AM

I would say that it's better that you use glob :-)

Runar 11-07-2008 10:48 AM

Like this? The code below is tested with positive result.

PHP Code:

<?php

// Turn on error reporting
ini_set'display_errors''yes' );

// Set path to our directory (for easier use)
// Remember the last slash (/)!
$directory_path 'your/image/folder/';

// Return .png files found in the directory
foreach( glob$directory_path '*.png' ) as $file )
{
    
// Put data in variables
    
$filename basename$file );
    
$filesize filesize$file );
    
    
// Do your database magic here
}
    
?>


Tanax 11-07-2008 10:55 AM

Quote:

Originally Posted by Runar (Post 19423)
Like this? The code below is tested with positive result.

PHP Code:

<?php

// Turn on error reporting
ini_set'display_errors''yes' );

// Set path to our directory (for easier use)
// Remember the last slash (/)!
$directory_path 'your/image/folder/';

// Return .png files found in the directory
foreach( glob$directory_path '*.png' ) as $file )
{
    
// Put data in variables
    
$filename basename$file );
    
$filesize filesize$file );
    
    
// Do your database magic here
}
    
?>


Correct!

Thought, he could also use it like this:
php Code:
glob($directory_path . '{*.png,*.jpg,*.gif}', GLOB_BRACE)

to support other than just .png that you had.

Read here: http://www.talkphp.com/absolute-begi...-way-glob.html

A great tutorial by Wildhoney.


All times are GMT. The time now is 02:03 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0