For wp_insert_attachment
and wp_generate_attachment_metadata
, change $file_name
in the following way.
$file_name = $upload_dir['path'] . "https://wordpress.stackexchange.com/" . basename($file_name);
WordPress codex for both function ( here and here ) says- ‘ Use absolute path and not the URI of the file. The file MUST be on the uploads directory’ $_FILES['fileUpload']
just gives the name of the file , not the absolute path along with.
Related Posts:
- Correct Syntax for uploading files to custom directory in WordPress
- Upload images and attachments from frontend form
- File upload, uploads only file name
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- Upload Image in a WordPress page using PHP
- Need help with Google drive API [closed]
- Attach previously uploaded image to post – current code has unexpected results
- wp_mail file attachment not being placed in upload folder?
- How to add post meta in while loop?
- How to get the filename from file system and create a download link?
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Post from front end form to post_meta
- File path for attachments outside of wp-content/uploads
- How to fix ‘Notice: Undefined index:’ in PHP form action
- How to add a class to the attachment images
- Genesis – Customize search form
- Change the filename format of saved featured images
- Check if user already visited this post today
- Using file_exists to check file in Uploads
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- How to display multiple Post meta_key/meta_values by SQL query
- Rename image uploads with width in filename
- Modify image while uploading
- On update to 3.04 site started recording accents as “á” and “á”, what to do?
- Save attachment custom fields on front end
- How can update custom meta for all posts
- Adding featured image via PHP
- How to enlarge the media file upload size in wordpress admin
- Use Timber/Twig to pull an image by image ID [closed]
- Implement a multi-value input field where the number of entries is not limited
- Use ajax to update_post_meta
- Adding a querystring to an image URL when clicking ‘insert into post’?
- wp_handle_upload – The uploaded file could not be moved to wp-content/uploads/2012/09
- Memory errors with media upload, WordPress can’t use more than 96M (while there’s 512 available!)
- Batch update a post meta field value of each post in Post Type
- Validate Uploaded Image using WordPress’ Built-in Functions?
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- woocommerce registration form with klaviyo(don’t work with current user)
- The text box have space character
- how to remove metadata from the posts of my blog?
- How can I create a list of page titles from custom meta values?
- Custom Form Processing Issue
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to store data from multiple forms using ajax and php
- How to use $query->set with post__in?
- PDF file randomly breaks upon upload
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Custom search results page not working with empty search
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- Can’t upload image using media_sideload_image
- Input data from email form not going to JSON file
- Archive post by meta value + 24hours
- Search Query: how to construct a search string from two select elements?
- Databases – Submitting data from inputs to database [closed]
- db converts decimal number wrong
- WordPress admin-ajax.php 400 bad request
- Is it possible to retrieve all posts with a certain value for metadata?
- Ajax contact form return 0
- Can I get an email notification when media is uploaded to the media library?
- Search WordPress using static html page
- How to put a form with php code into a variable or shortcode?
- Shortcode to embed Edit Account form not working
- Capture form data in one function and use it in another function (same file)
- How to store multiple custom meta box
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Update post meta – Custom field does not match meta-key
- File Uploader – Upload without adding to Media Library
- Custom upload folder
- Define category ID using get_post_meta
- WPDB secure custom form
- Adding attribute to the post.php form tag in wp-admin
- Update value of a associative array with update_post_meta
- Page Options Saving But Not Updating In Backend
- HTML Form Question
- Updating user meta adds string count to value?
- How to create a widget with a populated dropdown?
- Store user form submitted information in post type
- Hide author from search results meta, still display date and categories
- Javascript / PHP – closing the loop
- Updating the database after parsing CSV document
- Creating wordpress user registration form
- Adding user meta to post meta wp_insert_post() not working
- Upload images from one server to an other in wordpress
- Efficient way of querying for a “fallback” post?
- Passing link parameter values to form
- Processing forms with php to wordpress database
- Styling admin page rows in order of importance (checkboxes)
- Attachments doesn’t update
- Order by in foreach
- Is custom behaviour possible when asynchronously uploading?
- retrieve wordpress post-meta using php not wordpress functions
- get_post_meta no longer working
- Force string into signup form
- Data inserted in database, but ajax calls error function
- upload images on front by user using form
- Generate and upload screenshot as featured image for user-submitted post
- Pull latest Youtube Video from json url and make new post