There is no need to use the WP filesystem API if you are trying to access directories to which the web server has full access. It is needed mainly only when you want to write to directories which have limited access like the plugin directory. From that point of view the two snippets are the same.
What you are potentially doing wrong is trying to access a remote resource with file API. Your first snippet will fail on some hosts and I am totally not sure if the WP filesystem API will work.
A more robust way is to use the wordpress HTTP to get the content of the file with wp_remote_get
and save it to the uploads folders.
… last thing don’t do copyright infringements, too many people payed too much for such things.
Related Posts:
- Setting wp_temp_dir and permissions not working for “Missing A Temporary Folder” error
- Which filters or actions to use after a media upload and delete?
- Allowing all/different file type uploads
- Use WP_Filesystem to list files in directory
- wp_temp_dir does not change the /tmp temporary default directory
- Where is Featured Image code stored in WP?
- how to change max file upload size WordPress 4.9.8 [closed]
- Can’t write pdf file to upload directory using FPDF
- Change default uploads file using wp Skeleton
- Adding Adobe files to a wordpress site [closed]
- Placing assets for external use
- WordPress HTTP Error on File upload
- Interface for logged-in users to upload/download files
- WordPress Creates Unused (Unregistered) Image Sizes
- What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?
- Upload PDF and other files from the Front-End
- Uploaded images result in a file url with full path on disk appended
- temphangle variable missing when using wp_filesystem copy
- Where to store sensitive uploaded file?
- How to upload .tex files in wordpress?
- Downloadable content file structure
- Creating an .ics calendar subscription service with wordpress
- Should I use Filesystem API for reading files or listing directories?
- Private file system for attachments
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- Create image formats with different qualities when uploading
- wp_delete_attachment doesn’t delete images in wp-content/uploads/
- Force WordPress 3.3 to use Flash uploader
- Protecting direct access to PDF and ZIP unless user logged in (without plugin)
- How to add more upload directories?
- Multisite, upload images directly to Amazon S3
- How can I speed up a slow loading media library?
- What to do with unattached logos and header uploaded via native wordpress uploader?
- upload_mimes filter has no effect
- Impose a Maximum Limit on Image height and width upload size
- Force wordpress to see uploads folder media
- Moving Media Library
- Add item to media library from blob or dataUrl
- How do I enable the customize theme page to accept svg’s?
- Frontend Simple Local Avatar upload
- Disable TinyMCE Drag and Drop
- WP3.5 Media Uploader – how to make it accept multiple images?
- How to define a remote uploads directory?
- resize images not crop
- Trying to add filename over image in Media Browser
- How to hook into wordpress admin upload iframe?
- frontend upload return async-ajax.php 302
- How can I upload a file with no extension
- How to overwrite wp_unique_filename logic
- How to change upload directory based on frontend form input name or ID?
- How to check if txt file exists inside template folder?
- Cannot upload .mp3 file to wordpress media
- Flatten media files in uploads directory via linux terminal eliminating thumbnails?
- List and show uploaded pdf files dynamically
- WordPress Fancybox Resize Large Image
- XML-RPC: How to add media caption to uploaded image?
- wp_handle_upload() does not list uploaded file in the media library?
- The uploaded file could not be moved to wp-content/uploads/2019/07
- wordpress media upload given An error occurred in the upload. Please try again later
- Using wp_enqueue_media() with switch_to_blog() issue
- Uploading website to Host
- Local WordPress install plugin wont upload image
- What relationship determines which images appear in ‘uploaded to post’ in edit/add post media dialog
- Disable new WP3.5 Media Picker
- How to get the uploaded image url in media_handle_upload()?
- How to change format of file link ( Name ) when insert from media uploder
- Using dashboard uploader instead of FTP
- Use wp_handle_upload outside of a POST
- Moving Existing images from custom directory to WP’s upload directory
- admin notice on Insert Media popup screen
- How to allow .bin files upload?
- What is the URL pattern for image thumbnails + sizes?
- Setting up a HIPAA secured form / file upload
- How to make picture appear on wordpress site shared link? [closed]
- How to download files to WordPress?
- How to detect when a file has been uploaded?
- Cant upload larger than 100MB
- PDF Upload from Input Error
- Multiple images are generated in WP-content in wordpress
- Removing extra large generated images disables all crops
- MIME types not recognized by media library
- Missing a temporary folder not fixed
- How to allow .xls file uploads?
- Updating the attachment from front end doesn’t show the new change
- wp_update_attachment_metadata breaks after 10 files
- Media URL slugs without uploads folder path
- Add more field on WordPress media upload
- Frontend media shows “An error occurred in the upload. Please try again later.”
- File Upload Management
- Video limit about wordpress
- Can i add flickr,imgur etc. up-loader for my WP upload media button?
- Files larger than 500 kilobytes are not allowed
- get the post thumbnail returns the full size
- All files unattached in Media Library
- Media Upload Directory to MMYY instead of YYYY/MM
- Auto-Import of WXR File
- how upload images and videos to specific folder like wp-content\uploads\folder-name
- Media upload takes too long
- Problems with defining UPLOADS constant
- Create media folder upon post publish?