WordPress.org

Ready to get started?Download WordPress

Forums

how specify a directory to file when downloading it (3 posts)

  1. DrMosko
    Member
    Posted 9 months ago #

    I use this code to download a file from remote server to mine and the file is created and saved but in the home directory and i want it in the plugin directory

    $url ='*.dat';
    // Use wp_remote_get to fetch the data
    $response = wp_remote_get($url);
    
    // Save the body part to a variable
    $fileContent = $response['body'];
    
    // Create the name of the file and the declare the directory and path
    
    $file ='*.dat';
    
    // Now use the standard PHP file functions
    $fp = fopen($file, "w");
    fwrite($fp, $fileContent);
    fclose($fp);
  2. Rod Whiteley
    Member
    Posted 9 months ago #

    WordPress defines WP_PLUGIN_DIR as the full path of the plugins directory (with no trailing slash).

  3. DrMosko
    Member
    Posted 9 months ago #

    easy :
    $fp = fopen(plugin_dir_path( __FILE__ ).$file, "w");

Reply

You must log in to post.

About this Topic