| View previous topic :: View next topic |
| Author |
Message |
NoNameWill
Joined: Mon Sep 20, 2010 11:40 pm Posts: 18 Location: Seattle,WA
|
Posted: Mon Sep 20, 2010 11:57 pm Post subject: PHP Coding Academy Project 1 |
|
|
Hello,
I am getting this line in terminal when I run this script.
| Code: | PHP Warning: file_get_contents(output): failed to open stream: No such file or directory in /home/will/PHP/project1.php on line 22
|
There is a output file in PHP directory.
Here is what I have from following the instructions. I think I installed all the programs I need. I got them through SPM in Ubuntu 10.4.
I know I may have misinterpreted what was there. But I need some help. Thank you
| Code: | <?php
function subdir_scan($dir){
$files=scandir($dir);
foreach($files as $file){
if($file==".")continue;
if($file=="..")continue;
print "$dir/$file\n";
if(is_dir("$dir/$file")){
subdir_scan("$dir/$file");
}
}
}
chdir("..");
subdir_scan(".");
chdir("..");
ob_start();
subdir_scan(".");
$new_run=ob_get_clean();
$old_run=file_get_contents("output");
$new_array=explode("\n",$new_run);
$old_array=explode("\n",$old_run);
?>
|
Last edited by NoNameWill on Tue Sep 21, 2010 5:28 am; edited 1 time in total |
|
| Back to top |
|
 |
NoNameWill
Joined: Mon Sep 20, 2010 11:40 pm Posts: 18 Location: Seattle,WA
|
Posted: Tue Sep 21, 2010 1:03 am Post subject: |
|
|
I have gotten to the end of project one but I am getting this now
| Code: | PHP Warning: file_put_contents(output): failed to open stream: Permission denied in /home/will/PHP/project1.php on line 36
|
With this script
| Code: | <?php
function subdir_scan($dir){
$files=scandir($dir);
foreach($files as $file){
if($file==".")continue;
if($file=="..")continue;
print "$dir/$file\n";
if(is_dir("$dir/$file")){
subdir_scan("$dir/$file");
}
}
}
chdir("..");
subdir_scan(".");
chdir("..");
ob_start();
subdir_scan(".");
$new_run=ob_get_clean();
if(file_exists("output")){
$new_array=explode("\n",$new_run);
$old_run=file_get_contents("output");
$old_array=explode("\n",$old_run);
$differences=array_diff($new_array,$old_array);
foreach (differences as $file){
echo "New file detected:$file\n";
}
}
file_put_contents("output",$new_run);
?>
|
|
|
| Back to top |
|
 |
NoNameWill
Joined: Mon Sep 20, 2010 11:40 pm Posts: 18 Location: Seattle,WA
|
Posted: Tue Sep 21, 2010 6:22 am Post subject: |
|
|
| NoNameWill wrote: | I have gotten to the end of project one but I am getting this now
| Code: | PHP Warning: file_put_contents(output): failed to open stream: Permission denied in /home/will/PHP/project1.php on line 36
|
With this script
| Code: | <?php
function subdir_scan($dir){
$files=scandir($dir);
foreach($files as $file){
if($file==".")continue;
if($file=="..")continue;
print "$dir/$file\n";
if(is_dir("$dir/$file")){
subdir_scan("$dir/$file");
}
}
}
chdir("..");
subdir_scan(".");
chdir("..");
ob_start();
subdir_scan(".");
$new_run=ob_get_clean();
if(file_exists("output")){
$new_array=explode("\n",$new_run);
$old_run=file_get_contents("output");
$old_array=explode("\n",$old_run);
$differences=array_diff($new_array,$old_array);
foreach ($differences as $file){
echo "New file detected:$file\n";
}
}
file_put_contents("output",$new_run);
?>
|
|
|
|
| Back to top |
|
 |
Ram LXF regular

Joined: Thu Apr 07, 2005 10:44 pm Posts: 1569 Location: Guisborough
|
Posted: Tue Sep 21, 2010 8:55 am Post subject: |
|
|
Your scanning twice - have a look at this thread!!! _________________
Ubuntu LXDE 12.04 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
|
|
| Back to top |
|
 |
NoNameWill
Joined: Mon Sep 20, 2010 11:40 pm Posts: 18 Location: Seattle,WA
|
Posted: Tue Sep 21, 2010 4:57 pm Post subject: |
|
|
Now I see the error of my way. I did looked at that thread but it wasn't computing in my brain. Took a good nights rest to let it all set in.
Thank you for the help. Now off to figure out the challenge I am having in project 2.  |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|