I found that there’s a predefined WordPress function to upload a file into the Media Library but it’s only working asynchronously with a <form>
element and a $_FILES
array.
Second, I also found that there’s a second imagepng()
parameter filename which is the path where you want to save the file. I tried to save it to a WordPress uploads’ path such "/wp-content/uploads/$yyyy/$dd/filename.png"
but it’s not showing in the Media Library mostly because there’s no record of it from the database.
So, the best thing you could do is to save the image in the “/images” or “/img” folder of your theme directory and use the path of that directory:
$source = get_template_directory() . "/images/filename.png";
imagepng($im, $source);
Related Posts:
- How to register images uploaded via FTP in media library?
- Convert all images to PNG on file upload
- Redirect to another page using contact form 7? [closed]
- Convert all uploaded PNG files to PNG-8 format
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Generate and upload screenshot as featured image for user-submitted post
- Function to return true if current page has child pages
- How do I change/modify the_post_thumbnail(); html output?
- Proper use of Output Buffer
- List of all theme customizer control types?
- How to add a class to the attachment images
- Need help setting default setting value for radio button in theme customizer
- Adding a custom image upload size and making it selected by default?
- Change the filename format of saved featured images
- How to draw media details for Isotope gallery using Photoswipe
- function_exists call in function.php
- Create Image Uploader for Widget
- Using file_exists to check file in Uploads
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- Debugging an error: wp_enqueue_style was called incorrectly
- How to get the registered sidebar’s name by its id?
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- Rename image uploads with width in filename
- Dynamically change feature image in customiser
- One button to change all settings in theme customizer?
- Debugging upload problem: What part of WP does actual image-resizing?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- How to resize image on client-side before upload?
- Add custom image sizes to media uploader
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to upload imagick resource to media in wordpress
- Design view breaking on Pages
- Understanding WordPress child theme custom JS loading
- How can I loop into two different DIVS without repeating the DIVs
- Removing unnecessary wordpress files
- Remove css styles from specific page
- Is the regular ajax request method safe or I should use admin-ajax.php?
- How to get custom image size for image uploaded in Customizer
- Restrict WordPress File Type Uploads by User Type
- Using wp_get_image_editor in a standalone script
- How do I list the_tags() into HTML data-attribute
- Adding a querystring to an image URL when clicking ‘insert into post’?
- Can I change a variable in a content part while calling it?
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Change logo based on incoming domain
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- What is the fastest way to load PHP functions that are only used in one theme template?
- My Own layout in WooCommerce pages [closed]
- Validate Uploaded Image using WordPress’ Built-in Functions?
- Differences when using the the_time and the_date functions
- Get most recent media upload
- Can’t load WP function into external function
- Set WordPress Default Template
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- How to get specific image in media library with php
- Trigger popup in a php if/else statement
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Converting HTML Template to WordPress Theme
- Set the background to a default image if there isn’t a specified “featured image”
- How to remove the cufon script from Dzonia Lite theme [closed]
- How to control WordPress image metadata (using Imagick)?
- How do I add custom bulk actions to multiple custom post types?
- what is the best practice to add new field to an api route
- Error in custom php function doesn’t exist
- Can’t upload image using media_sideload_image
- Upload multiple images to a Woocomerce product
- Populate editor with some content of a page with a page template
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Enable custom logo upload if logo is not in header
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Scrape external webpage for first image and add it to new post
- Skt full width basic slideshow problem
- How to disable controls in theme customizer?
- How do I link a button I created in theme customizer to a function?
- Trying to retrieve post meta
- Is there a way to conditionally check whether a WordPress post title is empty?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- WordPress automatically adds links to uploaded images
- WordPress function when file is uploaded, deleted or edited
- WordPress admin-ajax.php
- Use .php file as page instead of wordpress page & template file?
- Use WordPress function in php file
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Adding php within a return statement [closed]
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- Load slideshow.css file only if Slideshow is checked / on
- add if statement to the featured image
- How can I fix my pagination?
- How to automatically convert images to WebP on WordPress?
- Remove default Image Sizes
- Understanding responsive imagery
- WooCommerce: write featured image dimensions to custom fields in product’
- require used as a function to load theme dependencies?
- How can we upload custom page files?
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?