PHP: copy() Permission Denied



  • I'm having a bit of an issue with copying a file using the copy() function in PHP. I'm getting an error, "<font color="#ff0000">
    Warning: copy(E:/apache2triad/htdocs/): failed to open stream: Permission denied in E:\apache2triad\htdocs\getpdf.php on line 41
    </font><font color="#ff0000">
    Warning: Cannot modify header information - headers already sent by
    (output

    started at E:\apache2triad\htdocs\getpdf.php:41) in
    E:\apache2triad\htdocs\getpdf.php on line 52</font>". The error-causing code looks like this (just for clarification, $filename, $userprefix, and $cert are all valid variables, declared previously, and the 4 replace lines have been proven to work properly):


    <font face="Courier New" size="1">

                $calfile = str_ireplace("\\data", "/docs/pdf", "$filename");
                $filepath = str_ireplace("k", "k_pdf", "$calfile");
                $pdffile = str_replace("\\", "/", str_ireplace("CAL","PDF",$filepath));
                $sourcefile = "E:/apache2triad/htdocs/$pdffile";


                if(file_exists("E:/apache2triad/htdocs/docs/customers/$userprefix/$cert.pdf"))
                {
                    header("Location: www.quantumcalibration.com/docs/customers/$userprefix/$cert.pdf");
                }
                elseif(copy($sourcefile, "E:/apache2triad/htdocs/docs/customers/$userprefix/$cert.pdf"))
                {
                    header("Location: www.quantumcalibration.com/docs/customers/$userprefix/$cert.pdf");
                }

    </font>

     Anyone see a glaring error somewhere?

     

    Regards,
    Brad Williams
    Northeast Metrology



  • If I recall how the header works, it can't be called after you've sent anything besides headers and cookies.  Maybe you've already sent something before this code gets executed.
     



  • Yes, that's correct. The header error is a result of the other error being sent to the screen. The real issue is the Permission Denied error that the copy() call is throwing... when that goes away, there won't be anything sent except the header() call, so it will work.

     

    Regards,
    Brad Williams
    Northeast Metrology



  • Does the web have rights to write to that directory?



  • It should... the server's Apache2 running on Win2k Server as the Local System account.



  • Would check into what rights the directory should have for which users.
    If it's saying permission denied, Permissions are being denied to write
    or read etc... somewhere..



  • It isn't a problem with reading from the source file (Apache can open the PDF file), and even if the destination directory's permissions are set to allow everyone to have full access, copy() is still throwing a Permission Denied.



  • Nevermind, this was programmer error... WTF-worthy, almost. I had declared $filename in code above what i had posted, but the line must have gotten deleted, as I do not have $filename in the code in front of me now. So the four replace lines end up making $pdffile an empty variable, so I'm actually trying to copy() the entire htdocs folder (error message shows the path only up to htdocs). Copy() doesn't work on folders, giving the Permission Denied error. D'oh.

     

    Regards,
    Brad Williams
    Northeast Metrology


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.