Page 1 of 1

File manipulation with PHP

Posted: Thu Oct 24, 2002 5:58 pm
by kenty
I'm trying to do something relatively simple(at least it should be!). I want to take a file that is below the web directory(not accessible) and copy it up into the web directory so that it can be accessed. This needs to be called inline in a php script so that I can copy the file - access the file in an active x script - then delete the file. I'm at then end of my rope and a newbie to boot! Based on the reading I've done this should work but it keeps failing. My only thought is that it's looking in a different path than I think it is - any help would be greatly appreciated.

Code: Select all

<?

$orig_filename = "test.html";


$success = @copy($orig_filename, $orig_filename.'.bak') or die("Couldn't copy file.");

if ($success) &#123;
	$msg =  "Copied $orig_filename to $original_filename.'bak'";
&#125; else &#123;
	$msg =  "Could not copy file.";
&#125;

?>

<HTML>
<HEAD>
<TITLE>Copy a File</TITLE>
</HEAD>
<BODY>

<? echo "$msg"; ?>

</BODY>
</HTML>

Posted: Thu Oct 24, 2002 6:33 pm
by hob_goblin
change

Code: Select all

$success = @copy($orig_filename, $orig_filename.'.bak') or die("Couldn't copy file.");
to

Code: Select all

$success = copy($orig_filename, $orig_filename.'.bak');
and see what PHP has to say.

thanks for the tip

Posted: Thu Oct 24, 2002 7:08 pm
by kenty
The error is this:

Warning: Unable to open '/home/catusr/test.html' for reading: No such file or directory in /home/webusr/html/kent_test/copy.php on line 6
Could not copy file

so basically I need to figure out how to make it start in the root directory when it goes to look for the file. Is that php.ini setting?

Thanks in advance for the help!

Posted: Thu Oct 24, 2002 7:21 pm
by hob_goblin
try using the full path.

path name

Posted: Thu Oct 24, 2002 8:49 pm
by phpScott
you can run a little script like this

Code: Select all

&lt;?php
   $root = getenv("DOCUMENT_ROOT"); 
   echo "root: ",$root,"&lt;br&gt;\n";
   
?&gt;
that will return some thing like:
root: /home/sites/site234/web
then rip of the /web or /public_html or the like.
then create a seperate file that defines a root variable

Code: Select all

&lt;?php
$ROOT='/home/sites/site234';
?&gt;
and then just include this file where ever needed.
your include path is hopefully outside the web directory and that would be a great place to store.

Thanks for the help everyone!

Posted: Thu Oct 24, 2002 10:20 pm
by kenty
With the debugging tips I was able to trace the problem to my linux file permissions(DUH!! :oops: )
I learned a lot in the meantime, so at least that's cool!
Thanks again for taking the time to help me out.


Kent