TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-07-2008, 03:27 AM   #1 (permalink)
The Wanderer
 
Join Date: Oct 2008
Posts: 14
Thanks: 0
Lou_Gato is on a distinguished road
Default 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
Lou_Gato is offline  
Reply With Quote
Old 11-07-2008, 08:11 AM   #2 (permalink)
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

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

Greetings,

Alex
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
Old 11-07-2008, 10:09 AM   #3 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

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
    
}
}
    
?>
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Old 11-07-2008, 10:38 AM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I would say that it's better that you use glob
__________________
Tanax is offline  
Reply With Quote
Old 11-07-2008, 10:48 AM   #5 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

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
}
    
?>
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Old 11-07-2008, 10:55 AM   #6 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Runar View Post
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: Traverse Directories the Easy Way with Glob() !

A great tutorial by Wildhoney.
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:09 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design