简体   繁体   中英

paths not working correctly with fopen/fwrite

I think it is something simple that has to do with my paths, because when I just create the files in the current folder, everything works. That being said, I am pretty unfamiliar with fopen(), fwrite(), and fclose(). The errors I am getting are (I think once the first one is fixed, the rest will work, too):

Warning: fopen(test/b/shipLabels/1_8154_0.pdf) [function.fopen]: failed to open stream: No such file or directory in /public_html/test/b/lib/FedEx/ShipWebServiceClient/Ground/Domestic MPS/ShipWebServiceClient.php5 on line 116

Warning: fwrite() expects parameter 1 to be resource, boolean given in /public_html/test/b/lib/FedEx/ShipWebServiceClient/Ground/Domestic MPS/ShipWebServiceClient.php5 on line 117

Warning: fclose() expects parameter 1 to be resource, boolean given in /public_Html/test/b/lib/FedEx/ShipWebServiceClient/Ground/Domestic MPS/ShipWebServiceClient.php5 on line 118

The lines that references are:

 $fp = fopen(SHIP_MASTERLABEL, 'wb');
     fwrite($fp, ($masterResponse->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image));
 fclose($fp);

I define SHIP_MASTERLABEL using this:

define('SHIP_MASTERLABEL', 'test/b/shipLabels/'.$clientId.'_'.$invoiceId.'_0.pdf');

In this case, $clientId=1, $invoiceId=8154. For the most part, this syntax has been provided by the FedEx docs.

Thanks so much for your help!

您最好使用绝对路径,并使用像DIR FILE这样的const等。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM