<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sat May 18, 2013 12:53 pm by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sat May 18, 2013 12:53 pm</pubDate>
  <lastBuildDate>Sat May 18, 2013 12:53 pm</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Re: PHP coding academy Page 25</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=91782#91782</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=66306'&gt;seancyril&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Aug 09, 2010 1:45 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hi Paul,  I am still not able to run the command without getting lots of error messages like those below. also the results of the scan are not being saved in an output directory. The new output directory is not being made at all&lt;br /&gt;
Sean&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
home/sean/.wine/dosdevices/z:/tmp/orbit-gdm): failed to open dir: Permission denied in /home/sean/PHP/project1.php on line 3&lt;br /&gt;
PHP Warning:  scandir(): (errno 13): Permission denied in /home/sean/PHP/project1.php on line 3&lt;br /&gt;
PHP Warning:  Invalid argument supplied for foreach() in /home/sean/PHP/project1.php on line 4</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=91782#91782</comments>
                                        <author>seancyril</author>
                                        <pubDate>Mon Aug 09, 2010 1:45 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=91782#91782</guid>
                                      </item>
                                      <item>
                                        <title>Re: PHP coding academy Page 25</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=91672#91672</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=66306'&gt;seancyril&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Aug 05, 2010 8:55 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Thanks for your reply. My permissions for the PHP directory are that I can read, write to it, it is also executable. The project1.php folder itself I can read and write to. don't know what I can change here in the permissions?&lt;br /&gt;
Sean</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=91672#91672</comments>
                                        <author>seancyril</author>
                                        <pubDate>Thu Aug 05, 2010 8:55 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=91672#91672</guid>
                                      </item>
                                      <item>
                                        <title>Re: PHP coding academy Page 25</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=91442#91442</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=21079'&gt;leke&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Jul 30, 2010 4:56 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      I'm not so good at programming, but maybe it could be...&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Quote:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;quote&quot;&gt;PHP Warning: scandir(): (errno 13): Permission denied in /home/sean/PHP/project1.php on line 3 &lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
Something to do with the set file permissions for that particular file or folder?&lt;br /&gt;
If this is the case, then it could lead to the foreach error because PHP expects something other than none in the loop.</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=91442#91442</comments>
                                        <author>leke</author>
                                        <pubDate>Fri Jul 30, 2010 4:56 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=91442#91442</guid>
                                      </item>
                                      <item>
                                        <title>Re: PHP coding academy Page 25</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=91440#91440</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=66306'&gt;seancyril&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Jul 30, 2010 3:43 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hi Paul, thanks for your reply I have changed the code so now it looks like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
function subdir_scan($dir) {&lt;br /&gt;
	 $files=scandir($dir);&lt;br /&gt;
	 foreach($files as $file) {&lt;br /&gt;
		if($file==&amp;quot;.&amp;quot;) continue;&lt;br /&gt;
		if($file==&amp;quot;..&amp;quot;) continue;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		print&amp;quot;$dir/$file\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		if(is_dir(&amp;quot;$dir/$file&amp;quot;)) {&lt;br /&gt;
&lt;br /&gt;
			  subdir_scan(&amp;quot;$dir/$file&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
			  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
chdir(&amp;quot;..&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
ob_start();&lt;br /&gt;
subdir_scan(&amp;quot;.&amp;quot;);&lt;br /&gt;
$output=ob_get_clean();&lt;br /&gt;
file_put_contents(&amp;quot;output&amp;quot;,$output); &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
I am now getting alot of error messages which I've given a sample of below. Is ther something wrong with my foreach() loop. Also I don't understand the permission denied message on line 3. &lt;br /&gt;
I appreciate you taking time out to help me with this. It's quite tricky when things go wrong with this stuff and you haven't got anyone to give advice&lt;br /&gt;
Sean&lt;br /&gt;
 in /home/sean/PHP/project1.php on line 3&lt;br /&gt;
PHP Warning:  scandir(): (errno 13): Permission denied in /home/sean/PHP/project1.php on line 3&lt;br /&gt;
PHP Warning:  Invalid argument supplied for foreach() in /home/sean/PHP/project1.php on line 4&lt;br /&gt;
PHP Warning:  scandir(./.wine/dosdevices/c:/users/sean/My Documents/.wine/dosdevices/c:/users/sean/My Documents/.wine/dosdevices/c:/users/sean/My</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=91440#91440</comments>
                                        <author>seancyril</author>
                                        <pubDate>Fri Jul 30, 2010 3:43 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=91440#91440</guid>
                                      </item>
                                      <item>
                                        <title>Re: PHP coding academy Page 25</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=91387#91387</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=6'&gt;Hudzilla&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Jul 29, 2010 8:30 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hey!&lt;br /&gt;
&lt;br /&gt;
The file isn't created because your script is actually running the scan twice - and you kill it while it's still running the first scan.&lt;br /&gt;
&lt;br /&gt;
Here:&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
chdir&amp;#40;&amp;quot;..&amp;quot;&amp;#41;; &lt;br /&gt;
subdir_scan&amp;#40;&amp;quot;.&amp;quot;&amp;#41;; &lt;br /&gt;
chdir&amp;#40;&amp;quot;..&amp;quot;&amp;#41;; &lt;br /&gt;
&lt;br /&gt;
ob_start&amp;#40;&amp;#41;; &lt;br /&gt;
subdir_scan&amp;#40;&amp;quot;.&amp;quot;&amp;#41;; &lt;br /&gt;
$output=ob_get_clean&amp;#40;&amp;#41;; &lt;br /&gt;
file_put_contents&amp;#40;&amp;quot;output&amp;quot;,$output&amp;#41;; &lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
That's your problem. See, unless you run ob_start(), everything you print to the command line is printed out straight away. In line 1, you change up to the parent directory - your home directory - which is correct. You then start a scan before you've started the output buffering, which is why you see everything printed out. You then (on line three) change up another directory, into /home presumably. Eventually you start output buffering and run the scan. I think what you're looking to do is this:&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
chdir&amp;#40;&amp;quot;..&amp;quot;&amp;#41;; &lt;br /&gt;
&lt;br /&gt;
ob_start&amp;#40;&amp;#41;; &lt;br /&gt;
subdir_scan&amp;#40;&amp;quot;.&amp;quot;&amp;#41;; &lt;br /&gt;
$output=ob_get_clean&amp;#40;&amp;#41;; &lt;br /&gt;
file_put_contents&amp;#40;&amp;quot;output&amp;quot;,$output&amp;#41;; &lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Let me know if that fixes your problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Paul</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=91387#91387</comments>
                                        <author>Hudzilla</author>
                                        <pubDate>Thu Jul 29, 2010 8:30 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=91387#91387</guid>
                                      </item>
                                      <item>
                                        <title>PHP coding academy Page 25</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=91332#91332</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=66306'&gt;seancyril&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Jul 28, 2010 11:40 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hi there, I am working my way (very slowly!) through the PHP coding academy book in this months mag and have come to another dead end. &lt;br /&gt;
I am trying to do the scan of my home directory and all subdirectories and sending the output to an &amp;quot;output&amp;quot; file located in my home directory as described on Page 25&lt;br /&gt;
However when I run the command I get a whole load of data that just flies past on the command line-this is my file tree for my home directory being printed out. However this data is not sent to an &amp;quot;output&amp;quot; file in my home directory nor even is this file created. I must admit that I have stopped the process as it is taking such a long time to print out all of my file tree in the command line. &lt;br /&gt;
Can anyone look at the code that I have printed out and see if I have made any mistakes?&lt;br /&gt;
&lt;br /&gt;
Many thanks&lt;br /&gt;
Sean&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
function subdir_scan($dir) {&lt;br /&gt;
	 $files=scandir($dir);&lt;br /&gt;
	 foreach($files as $file) {&lt;br /&gt;
		if($file==&amp;quot;.&amp;quot;) continue;&lt;br /&gt;
		if($file==&amp;quot;..&amp;quot;) continue;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		print&amp;quot;$dir/$file\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		if(is_dir(&amp;quot;$dir/$file&amp;quot;)) {&lt;br /&gt;
&lt;br /&gt;
			  subdir_scan(&amp;quot;$dir/$file&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
			  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
chdir(&amp;quot;..&amp;quot;);&lt;br /&gt;
subdir_scan(&amp;quot;.&amp;quot;);&lt;br /&gt;
chdir(&amp;quot;..&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
ob_start();&lt;br /&gt;
subdir_scan(&amp;quot;.&amp;quot;);&lt;br /&gt;
$output=ob_get_clean();&lt;br /&gt;
file_put_contents(&amp;quot;output&amp;quot;,$output);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=91332#91332</comments>
                                        <author>seancyril</author>
                                        <pubDate>Wed Jul 28, 2010 11:40 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=91332#91332</guid>
                                      </item></channel></rss>