1

I have a requirement to save a json file to disk.

I've got as far a the below php. However i get the following error.

fopen(/wp-content/content/uploads/artworks.js): failed to open stream: No such file or directory in

This file is in the correct location. So i assume there is a permission error. I only have ftp access to this server. Obviously wordpress has permission to write to disk. So how can i leverage this permission to save the file

$feed_url = 'http://example.com';
$remote_data = file_get_contents($feed_url);
$data = json_decode($remote_data, true);

$works = array();
foreach ($data ['rows'] as $inx => $remote_item_data) {
$works[] = $remote_item_data;
}


$fp = fopen('/wp-content/content/uploads/artworks.js', 'w+');
fwrite($fp, json_encode($works));
fclose($fp);

1 Answer 1

-2

try change to this one

$upload_dir = wp_upload_dir();
$fp = fopen( $upload_dir["basedir"] . '/artworks.js', 'w+');
1
  • Please, add a littel explanation of what the code does and how it can answer the question.
    – cybmeta
    Feb 6, 2016 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.