Articles of filesystem api

Right way to download file from source to destination

I’m trying to download a file from one location to another. The code is working perfect. Here is the code snippet: Helper Function – Create directory in /uploads/{$dir_name}/ and return paths. /** * Create folder in /uploads/{$dir_name}/ * @return array() */ function get_dirpath( $dir_name = ‘test’ ) { $wp_info = wp_upload_dir(); // SSL workaround. if […]

Is there function similar to wp_upload_bits() that will allow uploading to a specific path?

wp_upload_bits() allows you to put arbitrary binary data into a file, but it selects the path where the file is placed and doesn’t allow configuration of this destination besides the basename. There’s always the option of playing with the Filesystem API directly, but I was wondering if there is a similar function to wp_upload_bits() that […]

How to set path with WP_Filesystem and ftp base / chroot

In my theme i will use the WP_Filesystem to write a file to for example: $file = get_template_directory().’/library/assets/css/wpless2css.css’; Which outputs something like /home/user/domain/http_docs/wp-contents/theme/mytheme/library/assets/css/wpless2css.css This will work unless the ftp user will be chroot to /home/user/domain/ (on some servers?). In the case of a chroot the WP_Filesystem can’t find $file. A solution seems to define FTP_PATH […]

How to append_contents using WP_Filesystem?

I have scenario that appends the contents into the files, I was using normal file system function of PHP Now I have decided to use WordPress WP_Filesystem but I cannot see any methods of it which do append the contents into the files. It has only the put_contents(), Is there any way to append the […]

Why doesn't WP_Image_Editor save images using the Filesystem API?

I was in the process checking some of my existing plugins for any unsafe filesystem accesses, when I ran across WP_Image_Editor’s save function, which calls _save, which finally calls make_image (below). WP_Image_Editor was released in WP 3.5, while the Filesystem API has been around since WP 2.6, so I would presume that the reasoning is […]