PHP Coding Academy Project 1

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

PHP Coding Academy Project 1

Postby NoNameWill » Mon Sep 20, 2010 10:57 pm

Hello,

I am getting this line in terminal when I run this script.

Code: Select all
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: Select all
<?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 4:28 am, edited 1 time in total.
NoNameWill
 
Posts: 18
Joined: Mon Sep 20, 2010 10:40 pm
Location: Seattle,WA

Postby NoNameWill » Tue Sep 21, 2010 12:03 am

I have gotten to the end of project one but I am getting this now
Code: Select all
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: Select all
<?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);
?>
NoNameWill
 
Posts: 18
Joined: Mon Sep 20, 2010 10:40 pm
Location: Seattle,WA

Postby NoNameWill » Tue Sep 21, 2010 5:22 am

NoNameWill wrote:I have gotten to the end of project one but I am getting this now
Code: Select all
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: Select all
<?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);
?>
NoNameWill
 
Posts: 18
Joined: Mon Sep 20, 2010 10:40 pm
Location: Seattle,WA

Postby Ram » Tue Sep 21, 2010 7:55 am

Your scanning twice - have a look at this thread!!!

lubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
User avatar
Ram
LXF regular
 
Posts: 1676
Joined: Thu Apr 07, 2005 9:44 pm
Location: Guisborough

Postby NoNameWill » Tue Sep 21, 2010 3:57 pm

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. :D
NoNameWill
 
Posts: 18
Joined: Mon Sep 20, 2010 10:40 pm
Location: Seattle,WA


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests