简体   繁体   中英

PHP will not write file to directory via command prompt executed script but will write when executed in browser

I will execute this command in Command Prompt

php C:\xampp\htdocs\dl.php

These are the properties of my htdocs directory:

在此处输入图片说明

However, under the sharing tab, I have write permissions under all users:

在此处输入图片说明

I've restarted apache after each permission modification with no success. How do I fix this?

My PHP script downloads an XML file via an API and writes the XML file into the root directory of the server. When I execute www.mydomain.com/dl.php, the downloaded XML is written into the root directory; however, when I execute the PHP file (dl.php) via the command prompt, it will not write the downloaded file into the root directory.

PHP file:

$today = date("F j, Y").".xml";
$ch = curl_init ("");

$fp = fopen("ipod_car_connectors2.xml", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);

尝试将其更改为:

$fp = fopen("c:\\xampp\\htdocs\\ipod_car_connectors2.xml", "w");

  The solution was to escape slashes

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