Ryan
Ryan

Reputation: 14649

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:

enter image description here

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

enter image description here

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);

Upvotes: 0

Views: 1057

Answers (2)

Ryan
Ryan

Reputation: 14649

  The solution was to escape slashes

Upvotes: 0

djdy
djdy

Reputation: 6919

Try changing it to:

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

Upvotes: 1

Related Questions