473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

PHP file making from directory... Problem.

Here is my code and what it does is create a page for every directory with the contents of choice.

Its been working on all letters except "u" I can't seem to figure it out.

Does someone see the flaw that I'm not seeing?

[PHP]<?php
$dir_build = "../data/pages/";
$inside = array("0-9","A","B","C","D","E","F","G","H","I","J","K","L" ,"M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z ");

foreach($inside as $var){
$var = strtolower($var);
build($dir_build.$var."/");
}

//FOR ALPHA build($dir_build);

function build($dir){
if ($handle = opendir($dir)) {
$filecount = "0"; //reset the number of files
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && (!strstr($file,'.txt'))) { // remove the move up directory commands. (. and ..)
$file = strtolower($file); // make all filenames lowercase (looks better. can be removed)
$fileList[] = trim($file); // add the file to an array so it can be sorted easily.
$filecount = $filecount + 1; //count the number of files
}
}
if(is_array($fileList)){
sort ($fileList); // sort the file list in the array
reset ($fileList); // go back to the top of the array
closedir($handle);
}
}

if ($handle2 = opendir($dir)) { // read the current directory. Change the "." to the directory you need.
$filecount2 = "0"; //reset the number of files
while (false !== ($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != ".." && (strstr($file2,'.txt'))) {
$file2 = strtolower($file2); // make all filenames lowercase (looks better. can be removed)
$fileList2[] = substr(trim($file2),0,-4); // add the file to an array so it can be sorted easily.
$filecount2 = $filecount2 + 1; //count the number of files
}
}
if(is_array($fileList2)){
sort ($fileList2); // sort the file list in the array
reset ($fileList2); // go back to the top of the array
closedir($handle2);
}
}
if(is_array($fileList) && is_array($fileList2)){
$not_made = array_diff($fileList, $fileList2);
}

echo "<br /><br />The following were made in $dir<br />";
if($not_made){
foreach ($not_made as $value) {
$letter2 = $value{0};
if(is_int($letter2) || !$letter2){
$letter2 = "0-9";
}

$fh = fopen($dir.$value.".txt", 'w') or die("can't open file");
$value2 = ucwords(str_replace("."," ", $value));
$stringData = "My Data Here";
fwrite($fh, $stringData);
fclose($fh);
echo $dir.$value."<br />";
unset($value2); // break the reference with the last element
}
}
}
?>[/PHP]
Feb 25 '08 #1
2 1554
eragon
431 256MB
Is there an error your getting? And may i suggest, if it works fine for other files, then check your permissions. If theres any more info send it.
Mar 7 '08 #2
I did check permissions and no errors... its actually happening with x, q, and u. very awkward . Might have to redo whole script. :(
Mar 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Todd Johnson | last post by:
Hey, I have been working on a program that stores information for each user in a subdirectory of the directory in which the script is run. So if my script is in /home/someuser/myprogram, the...
6
by: o'seally | last post by:
solaris/linux admins/rookie_developers that battle with this error are probably all frustrated when it happens. i bet you're also somehow frustrated by this seemingly unsolvable error :-) ...take...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
23
by: da Vinci | last post by:
Greetings, Onwards with the school studying. Working on a program and need to delete a file from a known location on the hard drive but cannot get anything I do to work. I have tried to use...
1
by: keith russell | last post by:
Hi, I just transferred to another location at my company and am attempting to add some newly created webpages to their existing Windows Server 2003 Web Edition. I am new to ASP.Net, but have been...
1
by: Matthew Eno | last post by:
I have a problem where I'm developing some code that moves files from one place to another (on the same drive) with the destination file having a new name. What's happening is that the line of...
10
by: mrkcse | last post by:
I have choosed wise installation system 9.0 for making setup file of my vb6 application It is giving following error while creating setup " the following dependency files are referenced in...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
10
by: Raheem | last post by:
Hello, I built a development version of a live website on my hosted account. However the development version is having problems with finding include files. After troubleshooting I was able to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.