4

Please bear with me (I'm just learning how to use php). I can't figure out if my tidy error is related to an incorrect wget command or in itself. I thought my wget command was grabbing the remote file and placing it into my $link directory on my server...but something seems to be amiss.

I tried

  • changing the $tidy_cmd to single quotes
  • concatenating the line to "..." . $htmlDir . "/*";
  • not including the "/*"
  • using the php tidy commands (commented out...failed).

Error:

Error: Can't open "app/HtmlPages/arl.server.com-2015_11_19_15:36:09/arl.server.com/index.php/art"

wget.php:

    $ip = $argv[1];

    // Get the current time for the filename
    $currentTime = date( 'Y_m_d_H:i:s' );
    $link = "app/HtmlPages/$ip" ."-". "$currentTime";             
    $htmlDir = "$link/$ip/index.php/art";

    // Use wget to download aaron.htm webpage
    $wget_cmd = "wget -P $link/ http://$ip/index.php/art/aaron.htm";

    exec ( $wget_cmd );

    // Clean up the HTML for every page.
    $tidy_cmd = "tidy -config tidy_config.txt -i -m $htmlDir/*";
    exec ( $tidy_cmd );

    //$tidy_config = file_get_contents( 'tidy_config.txt' );
    //$tidy = new tidy();
    //$tidy->parseFile( '$htmlDir/*.htm', $tidy_config );
    ...
arl
  • 123
  • 1
  • 9
  • 1
    Looks like a simple path mistake to me. Print out all the paths before executing, like `echo "Downloading aaron.htm from http://" . $ip . "/index.php/art/aaron.htm to " . $link . "/";` you should also never put variables into strings, concatenate them with `.` like I did here. Some people might say you don't have to do this, but not doing it is bad practice. Another note: `curl` and `tidy` are available as extensions to PHP so you would not have to rely on executing in the shell. – Daniel W. Nov 19 '15 at 21:10
  • 1
    @DanFromGermany: You don't *have to* be consistent. You can use the terse version if it's appropriate. That *doesn't* make it bad practice. What you're *really* talking about, is a *style-guide*. Your company has this style-guide and it's fine. Just because somebody doesn't follow *your* company's style-guide doesn't make their practices bad. In the last enterprise PHP site I've worked on, plain `$var` inside a string was considered fine, but pretty much nobody used that or the two other forms because we used templates, with their own syntax. – Karoly Horvath Nov 23 '15 at 14:11
  • As a sidenote, dear moderators, *censored*, please don't clean up the *helpful* comments... – Karoly Horvath Nov 23 '15 at 14:18

1 Answers1

1

Looks like $htmlDir is relative to your source file (i.e., wget.php) whereas it needs to be an absolute path from the root of the filesystem (e.g., /home/yourname/yourfolder/and/so/on/). When you execute tidy it cannot read the file because the file does not exist, i.e., you provided it the wrong path. Try providing it an absolute path from the root of the filesystem and you should be good to go!

For future reference, it is helpful to debug this sort of thing by creating a test file that contains only the problematic code. In your case, just the bit that executes tidy. Then, you can execute that file on the command line with $ php test_script.php and hopefully that will make your debugging quicker and easier!

John Hall
  • 1,346
  • 13
  • 27