Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

so I've built this standalone php script which allows my users to upload a CSV which updates JSON data for a feature on our site, but I want to put the script inside of the wordpress admin section for obvious reasons.

So as a standalone script it works just fine, I can upload a CSV which the script converts to JSON and then it updates the file in the appropriate directory inside the wordpress theme.

Once moving this into WP however, Im getting errors because WP has already sent out headers (so I cant have my upload script redirect the use to the previous page) and probably related, I cant seem to open/create the JSON files any more.

failed to open stream: No such file or directory in blah blah blah.

Here is the code Im using to open/create the new JSON files:

$root_dir = dirname( dirname(__FILE__) );

if( $format == 'map'){

    $new_file = 'grading-data-'.$year.'.js';
    $target = $root_dir.'/js/reportcard/data/'.$new_file; 
}else{

    $new_file = 'states-data-'.$year.'.js';
    $target = $root_dir.'/js/reportcard/data/states/'.$new_file;    
}



$handle = fopen($target, "w+");
fwrite($handle, $output);
fclose($handle);

The script by the way, is located inside the theme folder. ie: theme> lib > upload_data > script.php

Now, because this is wordpress Im sure theres a very wordpressy way to do this but Im not sure where to look.

share|improve this question
    
Where is this file? Have you looked into the AJAX API? –  s_ha_dum Mar 20 at 17:49
    
the file is located in theme > js > reportcard > data > JSONFILE. I have not looked into it but Ill check that out. –  rugbert Mar 20 at 17:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.