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
Need help subdirectory
Old 05-09-2009, 03:18 PM Need help subdirectory
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
Hi
I'm not sure if I had a previuos post in regard to this problem.
I would like to upload all images from individual subdirectory (a-z) according to the first letter of the image name.
How can I add a code to this paath http://www.mysite/SEArchive/ to read from subdirectory. example: John.jpg path=http://www.mysite/SEArchive/J th for Mary.jpg the sub would be "M" path=http://www.mysite/SEArchive/M
I Hope you can help


[php]
<?PHP
$link = mysql_connect('localhost', 'xxx_xxx', 'xxx');
if (!$link) { die('Could not connect: ' . mysql_error()); }
mysql_select_db('xxx_xxx');

function find($name, $view){
global $link;

// Fetch total number of records
//$SQL="SELECT * FROM ihsreg WHERE Bloom_Name ='".addslashes($name)."'";
if(stristr($name,"'") && !stristr($name,"\'")){
$name = addslashes($name);
}
switch($view){
case "1": $column = 'Bloom_Name'; break;
case "2": $column = 'Pod_Name'; break;
case "3": $column = 'Pollen_Name'; break;
case "4": $column = 'Hybridiser'; break;
case "5": $column = 'Origin'; break;
default: $column = 'Bloom_Name'; break;

}

$SQL = "SELECT Bloom_Name, Pod_Name, Pollen_Name, Hybridiser, Origin " .
"FROM ihsreg " .
"WHERE " . $column . " LIKE '" . $name . "' AND $column != '' " .
"ORDER BY Bloom_Name ASC";
$result = mysql_query($SQL);
$results = array();
while($row = mysql_fetch_row($result)){
$results[] = $row;
}
return $results;
}
$noimagemessage = "No Photo Available";
if(isset($_GET['search'])){
//$fp = file('reg.txt');
//$search = "/".stripslashes($_GET['search'])."/i";
$search = $_GET['search'];
$y = 0;
$results[0]=Array();
$results[1]=Array();
$results[2]=Array();
$results[3]=Array();
$results[4]=Array();
//for($x=0; $x<count($fp); $x++){
/*
$search_text = "";
if($_GET['view']==5){
$search_text = split("\|",$fp[$x]);
$search_text = $search_text[4];
}else if($_GET['view']==4){
$search_text = split("\|",$fp[$x]);
$search_text = $search_text[3];
}else if($_GET['view']==3){
$search_text = split("\|",$fp[$x]);
$search_text = $search_text[2];
}else if($_GET['view']==2){
$search_text = split("\|",$fp[$x]);
$search_text = $search_text[1];
}else{
$search_text = split("\|",$fp[$x]);
$search_text = $search_text[0];
}
*/
$results = find($search,$_GET['view']);
/*
if(preg_match($search,$search_text)){
list($results[0][$y],$results[1][$y],$results[2][$y],$results[3][$y],$results[4][$y])=split("\|",$fp[$x]);
$y++;
}
*/
$y = sizeof($results);
//}
/*
if($_GET['view']==5){
array_multisort($results[4],$results[0],$results[1],$results[2],$results[3]);
}else if($_GET['view']==4){
array_multisort($results[3],$results[0],$results[1],$results[2],$results[4]);
}else if($_GET['view']==3){
array_multisort($results[2],$results[0],$results[1],$results[3],$results[4]);
}else if($_GET['view']==2){
array_multisort($results[1],$results[0],$results[2],$results[3],$results[4]);
}else{
array_multisort($results[0],$results[1],$results[2],$results[3],$results[4]);
}
*/
//echo '<PRE style="font-size: 9px;">';print_r($results);echo "</pre>";
}
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
img{
border:0;
}
</style>
<script type="text/javascript">
function open_win(img){
window.open("cvdata1.php?search="+img);
}
</script>
</head>
<body bgcolor="#FFFFFF" BACKGROUND="

Last edited by jd57; 05-10-2009 at 03:12 PM..
jd57 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-11-2009, 04:00 PM Re: Need help subdirectory
Extreme Talker

Posts: 177
Trades: 0
I'm a little confused by the question. You want to take a bunch of files in a directory(say directly root), and for each letter, put the files starting with that letter, in (root). So if there are 5 files named a*.jpg in root, you now want them to be root/a/a*.jpg.

If this is the case, you could iterate through each file in (root) and use
PHP Code:
 substr($filename01); 
which will get the first letter, and copy the file to the subdirectory of root, and then delete the file in root.

Last edited by kbfirebreather; 05-11-2009 at 04:01 PM.. Reason: changed php code
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 05-12-2009, 04:55 AM Re: Need help subdirectory
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
I’m sorry if I did not explain myself and made a lot of confusion, I will try to explain better this time (I Hope)
I used to have all of my images in one folder roo/SEArchive but because of the huge amount of files in one directory I had to create 26 subdirectories from “A” – “Z” and moved all images that start with “a” to the “A” subdirectory all “b” to the “B” subdirectory…etc
Since I made this change I need to modify the path to read from the individual subdirectory,
What change I need to make so that it works?
jd57 is offline
Reply With Quote
View Public Profile
 
Old 05-12-2009, 10:31 AM Re: Need help subdirectory
Extreme Talker

Posts: 177
Trades: 0
Unfortunately I'm still a little confused about exactly what you're trying to accomplish. Are you trying to have these folders kind of act like a directory? So if you go to url/images/a in a web browser, then it will list all the files in that directory, and link to them?

And just to be sure, you already moved all a*.jpg to /A, b*.jpg to /B, etc..., right?

Assuming you want to list each file in each directory, you can just put an index.php in each subdirectory (A, B, C....Z) with the source of this....

PHP Code:
// directory path can be either absolute or relative
$dirPath '.';

// open the specified directory and check if it's opened successfully 

$url $_SERVER['REQUEST_URI'];
if (
$handle opendir($dirPath)) {
    
$x 0;
   
// keep reading the directory entries 'til the end 
   
while (false !== ($file readdir($handle))) {
      
// just skip the reference to current and parent directory 
      
if ($file == "..") {
         if (
is_dir("$dirPath/$file") && $url != "/files/") {
            
$x++;
            
// found a directory, do something with it? 
            
echo "<a href='$file'>[$file]</a><br/>";
         }
      }
   }
   
if(
$x != 0)
   {
    echo 
'<br /> <br />';
    }
   
// ALWAYS remember to close what you opened 
   
closedir($handle);
}

//DISPLAY FILES
if ($handle opendir($dirPath)) {
    
$x 0// for directories
    
$y 0// for files
    
while (false !== ($file readdir($handle))) {
      
// just skip the reference to current and parent directory 
      
if ($file != "." && $file != ".." && $file != "index.php") {
         if (
is_dir("$dirPath/$file")) {
            
$dirs[$x] = ($file);
            
$x++;
            
// FOUND A DIRECTORY
         
} else {
            
$files[$y] = ($file);
            
$y++;
            
// found an ordinary file 
         
}
      }
   }
  
//SORTS CASE INSENSITIVE

//PRINTS OUT DIRECTORIES
if($x 0)
{
    
natcasesort($dirs);
    foreach(
$dirs as $dir)
    {
        echo 
"<a href='$dir'>[$dir]</a><br />";
    }
    if(
sizeof($dirs) > 0)
    {
        echo 
'<br /><br />';
    }
}

//PRINTS OUT FILES
if($y 0)
{
    
natcasesort($files);
     foreach(
$files as $file)
    {
        echo 
"<a href='$file'>$file</a><br/>";
    }

    
// ALWAYS remember to close what you opened 
    
closedir($handle);
}

What this does is reads everything in the current directory, and if it's a file, puts it into a file array, if it's a directory puts it in a directory array, then once it iterates through all objects in the current directory it will output all the directories in alphabetical order, then all the files in alphabetical order, disregarding extension for when it gets alphabetized.

ORRR are you trying to have 1 index.php file in the root directory that scans all the sub directories and displays what this php code is doing for reach directory... but in one page. So you wouldn't have to click on each subdirectory (like my php code allows you to do) to see the other files.

I feel like I'm making this sound confusing.

Do you need what my code is doing and have 26 index.php files.

Or do you want 1 index.php file that displays all pictures (and links to them?) for each subdirectory?

If the latter were the case, then you could just modify the php source in my post do use recursion on each subdirectory and keep putting those files in the the file, array. Then once you have iterated through each directory and subdirectory, you could output all the files.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 05-12-2009, 12:47 PM Re: Need help subdirectory
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
ok that's it thank you very much
jd57 is offline
Reply With Quote
View Public Profile
 
Old 05-12-2009, 12:55 PM Re: Need help subdirectory
Extreme Talker

Posts: 177
Trades: 0
Awesome, glad I could help. Out of curiosity, did you go the route with the index.php in each sub directory, or the route of recursively iterating through each sub directory and grabbing each file?
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help subdirectory
 

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.28567 seconds with 12 queries