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

  1. DrMosko
    Posted 2 years 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);
  2. Rod Whiteley
    Posted 2 years ago #

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

  3. DrMosko
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic