Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
using "while" in array creating duplicates
Old 08-21-2007, 01:21 PM using "while" in array creating duplicates
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
Hello, I am writing a script that unzips a file and goes through the images and copys them to another directory. The problem I'm having is the while php command is duplicating some entries

Say I have 5 images in a folder, it makes 5 images but 4 of those are duplicates. Any way around this?


heres my code:

PHP Code:

 
while (list($var$img) = each($images))  {
  
   
$thefile =  $img['file'];
     
$thefilename =  $img['filename'];
    
$ext =  file_extension($thefile);

        
srand(time());
            
$filename = (rand()%1000000000);
            
            
            
$photo $filename.".".$ext;
            
$uploaded_file_thumb '../images/gallery/'.$filename.".".$ext;
            
$uploaded_file_thumb '../images/gallery/thumbs/'.$filename.".".$ext;
    
            
$rimg=new RESIZEIMAGE($thefile);
            
$rimg->resize_limitwh("750","350",$uploaded_file);
            
$rimg->resize_limitwh("100","110",$uploaded_file_thumb);
            
$rimg->close();
            
        
            
    
        
$query$database->insert("gallery"
            
"name, description, cat"
            
"'$photo', '$description', '$cat'");
    
    
    
    
  } 
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
 
Register now for full access!
Old 08-21-2007, 02:08 PM Re: using "while" in array creating duplicates
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I may see a possible problem, but I'm not sure.

you do
PHP Code:
srand(time()); 
$filename = (rand()%1000000000); 
First there is no need for it.
Second, the modulo with such a big value could reduce it to a value that might have collisions.

I'd recommand you to try to replace this bit with an uniqid() call.
http://www.php.net/manual/en/function.uniqid.php
PHP Code:
$filename=md5(uniqid(rand(), true)); 
Maybe this could solve your problem.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to using "while" in array creating duplicates
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09835 seconds with 12 queries