Kris with a K Kris with a K - 1 year ago 105
PHP Question

"No such file or directory" on localhost copy

EDIT: I'm pretty sure the issue has to do with the firewall, which I can't access. Marking Canis' answer as correct and I will figure something else out, possibly wget or just manually scraping the files and hoping no major updates are needed.

EDIT: Here's the latest version of the builder and here's the output. The build directory has the proper structure and most of the files, but only their name and extension - no data inside them.

I am coding a php script that searches the local directory for files, then scrapes my localhost (xampp) for the same files to copy into a build folder (the goal is to build php on the localhost and then put it on a server as html).

Unfortunately I am getting the error:

Warning: copy(https:\\localhost\intranet\builder.php): failed to open stream: No such file or directory in C:\xampp\htdocs\intranet\builder.php on line 73
.

That's one example - every file in the local directory is spitting the same error back. The source addresses are correct (I can get to the file on localhost from the address in the error log) and the local directory is properly constructed - just moving the files into it doesn't work. The full code is here, the most relevant section is:

// output build files
foreach($paths as $path)
{
echo "<br>";
$path = str_replace($localroot, "", $path);
$source = $hosted . $path;
$dest = $localbuild . $path;

if (is_dir_path($dest))
{
mkdir($dest, 0755, true);
echo "Make folder $source at $dest. <br>";
}
else
{
copy($source, $dest);
echo "Copy $source to $dest. <br>";
}
}

Answer Source

You are trying to use URLs to travers local filesystem directories. URLs are only for webserver to understand web requests. You will have more luck if you change this:

copy(https:\\localhost\intranet\builder.php)

to this:

copy(C:\xampp\htdocs\intranet\builder.php)

EDIT

Based on your additional info in the comments I understand that you need to generate static HTML-files for hosting on a static only webserver. This is not an issue of copying files really. It's accessing the HMTL that the script generates when run through a webserver.

You can do this in a few different ways actually. I'm not sure exactly how the generator script works, but it seems like that script is trying to copy the supposed output from loads of PHP-files.

To get the generated content from a PHP-file you can either use the command line php command to execute the script like so c:\some\path>php some_php_file.php > my_html_file.html, or use the power of the webserver to do it for you:

<?php
foreach($paths as $path)
{
    echo "<br>";
    $path = str_replace($localroot, "", $path); 
    $source = $hosted . $path;
    $dest = $localbuild . $path;

    if (is_dir_path($dest))
    {
        mkdir($dest, 0755, true);
        echo "Make folder $source at $dest. <br>";
    }
    else
    {
        $content = file_get_contents(urlencode($source));
        file_put_contents(str_replace(".php", ".html", $dest), $content);
        echo "Copy $source to $dest. <br>";
    }
}

In the code above I use file_get_contents() to read the html from the URL you are using https://..., which in this case, unlike with copy(), will call up the webserver, triggering the PHP engine to produce the output.

Then I write the pure HTML to a file in the $dest folder, replacing the .php with .htmlin the filename.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download