Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Front end file upload returning wrong attachment url

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:

  1. Correct Syntax for uploading files to custom directory in WordPress
  2. Upload images and attachments from frontend form
  3. File upload, uploads only file name
  4. is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
  5. Upload Image in a WordPress page using PHP
  6. Need help with Google drive API [closed]
  7. Attach previously uploaded image to post – current code has unexpected results
  8. wp_mail file attachment not being placed in upload folder?
  9. How to add post meta in while loop?
  10. How to get the filename from file system and create a download link?
  11. Problem with inserting multiple images in gallery of each WooCommerce product programmatically
  12. Post from front end form to post_meta
  13. File path for attachments outside of wp-content/uploads
  14. How can I reuse the code to capture a param in a URL and place in a value in a hidden form?
  15. WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
  16. How to store data from multiple forms using ajax and php
  17. How to use $query->set with post__in?
  18. PDF file randomly breaks upon upload
  19. Ajax loaded form replaces form action with Ajax url
  20. prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
  21. Sort custom meta column by other meta value
  22. How to limit the number of forgot password reset attempts in WordPress?
  23. Custom search results page not working with empty search
  24. Modify HTML structure of fields in woocommerce checkout form
  25. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  26. Image upload via FormData API and AJAX is not working ($_FILES always empty)
  27. How to upload a file to a folder named after the user_id via plugin
  28. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  29. Creating user status mode in WordPress
  30. Can’t upload image using media_sideload_image
  31. Send multiple attachments with wp_mail in PHP
  32. Upload multiple images to a Woocomerce product
  33. Post + form + action + results on the same page
  34. Ajax call return 404
  35. How to pre populate a form field with a link of a current user’s author profile?
  36. Why Won’t My Inputs in a form with a Get method work together?
  37. What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
  38. Input data from email form not going to JSON file
  39. How to get the value of input hidden html from text editor to custom page template?
  40. Upload file could not be moved to wp-content/uploads
  41. Enable custom logo upload if logo is not in header
  42. NGINX rewrite rules for multisite
  43. Archive post by meta value + 24hours
  44. Show success or error messages in Ajax response to WordPress custom registration form
  45. Styling my own password protected page, how to deal with wrong password?
  46. WordPress update_post_meta updating with empty meta_value field [closed]
  47. Contact form won’t submit
  48. How do I get around “Sorry, this file type is not permitted for security reasons”?
  49. Search Query: how to construct a search string from two select elements?
  50. Login to wordpress by clicking a link and specifying usernaname and password in url
  51. Databases – Submitting data from inputs to database [closed]
  52. How to show a ‘correct’ message after submit a form?
  53. Change WordPress Upload Folder using wp handle upload
  54. db converts decimal number wrong
  55. Form Security: nonce vs. jQuery
  56. How do I Import / Upload Files with jQuery AJAX?
  57. WordPress admin-ajax.php 400 bad request
  58. WordPress automatically adds links to uploaded images
  59. WordPress function when file is uploaded, deleted or edited
  60. Is it possible to retrieve all posts with a certain value for metadata?
  61. Get post id within comments loop
  62. Ajax contact form return 0
  63. Can I get an email notification when media is uploaded to the media library?
  64. Trying do build a contact form
  65. “operation successful” message
  66. Non-Closing PHP Query in WordPress Loop
  67. Returning data instead of echoing/printing
  68. User register hook is not working in woocomerce register form
  69. Search WordPress using static html page
  70. Blob file download problem
  71. How to execute html code inside php?
  72. Querying Database with wpdb
  73. zip unzip attachments in wordpress
  74. How to put a form with php code into a variable or shortcode?
  75. update_post_meta only updating on last loop of foreach
  76. Can a page contain php code?
  77. How to send form data from WordPress (Meta Box) to an OData service?
  78. how to get serialized post meta
  79. How to use two meta_compare in an array?
  80. Upload multiple files in randomly generated folder using wp_upload_bits
  81. What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
  82. WordPress shortcode returns the data before
  83. Shortcode to embed Edit Account form not working
  84. Form Submission Not Working In Custom Theme
  85. Capture form data in one function and use it in another function (same file)
  86. Remove empty terms from array, sort alphabetically, update back to repeating field
  87. WordPress loop by meta key that is an array? and how loop multiple arrays
  88. WordPress yoast seo plugin – parse snippet var in meta description
  89. Can’t upload CSV file to plugin directory using custom upload form in admin panel
  90. How to store multiple custom meta box
  91. How to display success message correctly and delete it when the page is refreshed
  92. Using admin-post.php for admin form but it directs me to admin-post.php white screen
  93. WordPress upload file size error even after raising php limits
  94. Why does my user not get added to the database on custom registration?
  95. Get uploaded image and attach it to the new post
  96. Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
  97. Add category to post meta
  98. Using rules in Posts
  99. Get featured image with custom size outside WordPress
  100. Why is my max_upload_filesize being limited to 2M? [duplicate]
Categories PHP Tags attachments, forms, php, post-meta, uploads
Taxonomy term archive default loop returns 1 record instead of 8
Custom post type title of each author in his own post

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress