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 can I reuse the code to capture a param in a URL and place in a value in a hidden form?
- 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
- Sort custom meta column by other meta value
- How to limit the number of forgot password reset attempts in WordPress?
- Custom search results page not working with empty search
- Modify HTML structure of fields in woocommerce checkout form
- 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)
- How to upload a file to a folder named after the user_id via plugin
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Creating user status mode in WordPress
- Can’t upload image using media_sideload_image
- Send multiple attachments with wp_mail in PHP
- Upload multiple images to a Woocomerce product
- Post + form + action + results on the same page
- Ajax call return 404
- How to pre populate a form field with a link of a current user’s author profile?
- Why Won’t My Inputs in a form with a Get method work together?
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Input data from email form not going to JSON file
- How to get the value of input hidden html from text editor to custom page template?
- Upload file could not be moved to wp-content/uploads
- Enable custom logo upload if logo is not in header
- NGINX rewrite rules for multisite
- Archive post by meta value + 24hours
- Show success or error messages in Ajax response to WordPress custom registration form
- Styling my own password protected page, how to deal with wrong password?
- WordPress update_post_meta updating with empty meta_value field [closed]
- Contact form won’t submit
- How do I get around “Sorry, this file type is not permitted for security reasons”?
- Search Query: how to construct a search string from two select elements?
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Databases – Submitting data from inputs to database [closed]
- How to show a ‘correct’ message after submit a form?
- Change WordPress Upload Folder using wp handle upload
- db converts decimal number wrong
- Form Security: nonce vs. jQuery
- How do I Import / Upload Files with jQuery AJAX?
- WordPress admin-ajax.php 400 bad request
- WordPress automatically adds links to uploaded images
- WordPress function when file is uploaded, deleted or edited
- Is it possible to retrieve all posts with a certain value for metadata?
- Get post id within comments loop
- Ajax contact form return 0
- Can I get an email notification when media is uploaded to the media library?
- Trying do build a contact form
- “operation successful” message
- Non-Closing PHP Query in WordPress Loop
- Returning data instead of echoing/printing
- User register hook is not working in woocomerce register form
- Search WordPress using static html page
- Blob file download problem
- How to execute html code inside php?
- Querying Database with wpdb
- zip unzip attachments in wordpress
- How to put a form with php code into a variable or shortcode?
- update_post_meta only updating on last loop of foreach
- Can a page contain php code?
- How to send form data from WordPress (Meta Box) to an OData service?
- how to get serialized post meta
- How to use two meta_compare in an array?
- Upload multiple files in randomly generated folder using wp_upload_bits
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- WordPress shortcode returns the data before
- Shortcode to embed Edit Account form not working
- Form Submission Not Working In Custom Theme
- Capture form data in one function and use it in another function (same file)
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- WordPress yoast seo plugin – parse snippet var in meta description
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- How to store multiple custom meta box
- How to display success message correctly and delete it when the page is refreshed
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- WordPress upload file size error even after raising php limits
- Why does my user not get added to the database on custom registration?
- Get uploaded image and attach it to the new post
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Add category to post meta
- Using rules in Posts
- Get featured image with custom size outside WordPress
- Why is my max_upload_filesize being limited to 2M? [duplicate]