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 06-09-2009, 06:52 PM   #1 (permalink)
The Contributor
Newcomer 
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 93
Thanks: 10
Peuplarchie is on a distinguished road
Application Can't make it to sort...

Good day to you all,
here i'm working on a function that read a directory, for each folder show its images.

Here's the part that don't work :
No error but don't sort while it list files it should also sort them , Portrait, Landscape, Panoramic.

Here is my code :
PHP Code:



<?php

        
         set_time_limit
(0);
        

        
        
$directory $_GET['dir'];

// Function that read a directory list of folder and result them
function getDirectory$path '.'$level ){

    
$ignore = array( 'cgi-bin''.''..' );
    
// Directories to ignore when listing output. Many hosts
    // will deny PHP access to the cgi-bin.

    
$dh = @opendir$path );
    
// Open the directory to the handle $dh
    
    
while( false !== ( $file readdir$dh ) ) ){
    
// Loop through the directory
    
        
if( !in_array$file$ignore ) ){
        
// Check that this file is not to be ignored
            
            
$spaces str_repeat'&nbsp;', ( $level ) );
            
// Just to add spacing to the list, to better
            // show the directory tree.
            
            
if( is_dir"$path/$file" ) ){
            
// Its a directory, so we need to keep reading down...
            

//Creating var for Portrait images list    
    
$portrait "";
//Creating var for Landscape images list    
$landscape "";
//Creating var for panoramic images list    
$panoramic "";
//Read that directory
$files scandir($path."/".$file);
// Echo the name
echo "<div id=\"bar\"><b>".$file."</b></div><br/>";
echo 
"<div>";

//For each file in tha folder
foreach($files as $key => $value){
    
    if (
$value != "." && $value != "..") {
        
        
//Substring to $value his last 5 char
        
$formatfind =  substr($value,-5);
        
// Subtracting to this the last 4
        
$format =  substr($formatfind,0,-4);
        
//This is in my naming convension.Portrait equal 1    landscape equal 0 and panoramic equal 2
        
    // if file $format equal 1
    
if ($format "1") {
// add it to portrait list
    
$portrait .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$path."".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$portrait .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$portrait .= "<img src=\"".$path."".$file."/".$value."\" /><br />".$value."<br/></div>";
    }
    
// if  file $format equal 0    
    
if ($format "0") {
    
$landscape .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$landscape .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$landscape .= "<img src=\"".$file."/".$value."\" /><br />".$value."<br/></div>";
    
    }
    
    
// if  file $format equal 2    
    
if ($format "2") {
    
$panoramic .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$panoramic .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$panoramic .= "<img src=\"".$file."/".$value."\" /><br />".$value."<br/></div>";
    
    }
  
// Else, do nothing
    
}else{
        
        
        }
    
}
// echo result of the 3 format
echo $portrait;
echo 
"<br/>";
echo 
$landscape;
echo 
"<br/>";
echo 
$panoramic;

echo 
"</div>";
echo 
"<br/>";
                
                
          
            }
        
        }
    
    }
    
// close diretory
    
closedir$dh );
    
// Close the directory handle


        
        
// calling the function
         
getDirectory$directory );
        
        
 
?>

Thanks !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 06-09-2009, 07:11 PM   #2 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 60
Thanks: 20
Runar is on a distinguished road
Default

What do you mean by "it should also sort them"? And have you tried the code I posted in your first thread?
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Old 06-10-2009, 12:23 PM   #3 (permalink)
The Wanderer
 
Schroder's Avatar
 
Join Date: Mar 2008
Posts: 18
Thanks: 0
Schroder is on a distinguished road
Default

If I'm understanding the problem correctly, I think the issue is in this section of code:

PHP Code:
    // if file $format equal 1
    
if ($format "1") {
// add it to portrait list
    
$portrait .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$path."".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$portrait .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$portrait .= "<img src=\"".$path."".$file."/".$value."\" /><br />".$value."<br/></div>";
    }
    
// if  file $format equal 0    
    
if ($format "0") {
    
$landscape .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$landscape .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$landscape .= "<img src=\"".$file."/".$value."\" /><br />".$value."<br/></div>";
    
    }
    
    
// if  file $format equal 2    
    
if ($format "2") {
    
$panoramic .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$panoramic .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$panoramic .= "<img src=\"".$file."/".$value."\" /><br />".$value."<br/></div>";
    
    }
  
// Else, do nothing
    
}else{
        
        
        } 
An assignment operator (=) is being used instead of a comparison (==), so the 1, 2 and 3 are being assigned to $format. There is no error returned because this is still valid, and it will return true.

Below is how it probably should look:
PHP Code:
    // if file $format equal 1
    
if ($format == "1") {
// add it to portrait list
    
$portrait .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$path."".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$portrait .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$portrait .= "<img src=\"".$path."".$file."/".$value."\" /><br />".$value."<br/></div>";
    }
    
// if  file $format equal 0    
    
if ($format == "0") {
    
$landscape .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$landscape .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$landscape .= "<img src=\"".$file."/".$value."\" /><br />".$value."<br/></div>";
    
    }
    
    
// if  file $format equal 2    
    
if ($format == "2") {
    
$panoramic .= "<a onmouseover=this.style.cursor=\"pointer\" ' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'block' \" ><img src=\"".$file."/".$value."\" width=\"50px\" class=\"imag\"></a>\n"
    
$panoramic .= "<div id='".$value."' style='display: none;  position: absolute;  text-align:left; margin: 0px -300px; margin-top:-150px;  z-index:50; border: solid black 1px; padding: 10px; background-color: #ffffff; text-align: justify; font-size: 12px; onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('".$value."').style.display = 'none' \" >";
    
$panoramic .= "<img src=\"".$file."/".$value."\" /><br />".$value."<br/></div>";
    
    }
  
// Else, do nothing
    
}else{
        
        
        } 
Schroder 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tips to Improve Your Coding and Projects Village Idiot Tips & Tricks 42 11-08-2009 06:53 PM
How do I make a tree view from MySQL and PHP oscargodson General 3 12-10-2008 01:22 PM
Where would i start to make... Patriotfan Absolute Beginners 15 07-27-2008 09:36 PM
Make Your Own PHP Flash Player Which You Can Pass a File Variable with Preview!!!! thegrayman Tips & Tricks 2 12-11-2007 11:44 PM
how to sort this???? meshi Absolute Beginners 3 10-24-2007 04:49 PM


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

 
     

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