• DrMosko

    (@drmosko)


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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Rod Whiteley

    (@rod-whiteley)

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

    Thread Starter DrMosko

    (@drmosko)

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how specify a directory to file when downloading it’ is closed to new replies.