Articles of wp handle upload

Upload multiple image with media_handle_upload with multiple file field

This question already has an answer here: Upload Multiple Files With media_handle_upload 3 answers

Ajax image upload with media_handle_upload and form.js

I want to have AJAX image upload on front-end form and can’t figure out where it goes wrong. HTML form for image upload <form id=”thumbnail_upload” method=”post” action=”#” enctype=”multipart/form-data” > <input type=”file” name=”thumbnail” id=”thumbnail”> <input type=’hidden’ value='<?php wp_create_nonce( ‘upload_thumb’ ); ?>’ name=’_nonce’ /> <input type=”hidden” name=”action” id=”action” value=”my_upload_action”> <form> <div id=”output1″></div> <script> jQuery(document).ready( function($) { //http://wordpress.stackexchange.com/questions/72406/set-featured-image-front-frontend-form […]

How to adapt upload_dir to save files outside of WP uploads folder

We have a CPT which is used to manage various assets including image, pdf, CAD and other files. Our client would like to keep these asset files seperate from their other media files and does NOT want them to appear in the WP media panel. We have found this useful snippet which allows us to […]

Change file name on upload in Media Page

I trying to program the following rules: When attachment uploaded on wp-admin/post.php page, on the act of uploading, rename it to {post-slug}-{n}-[WxH].{ext} When attachment uploaded on wp-admin/upload.php page, on the act of uploading, rename it to {site-name}-{n}-[WxH].{ext} Where {n} is the numerical order, [WxH] the sizes applied by WordPress and {ext} its extension. Item 1 […]

Is it possible for a plugin to force reading and writing of uploaded images to a database instead of to a filesystem?

I am trying to configure a WordPress site using a server cluster and independent file systems. The problem is keeping the wp_content/uploads folder synchronized across all the server instances. My preferred solution is to “write” and “read” these files to/from a shared database. So my basic question is whether this is possible to code in […]

Upload images and attachments from frontend form

I’m not very expert of wordpress and I’m trying to create a frontend form sending information to my php function through ajax. I’d need help about uploading images and files as attachments of the post. My jQuery / Ajax is sending everything correctly to my php file. The only thing I don’t understand is why […]

Change WordPress Upload Folder using wp handle upload

Below code is for uploading file through a form … I want to change the default upload path for the upload to a folder called abc in the root of my theme. I hope somebody can help me with this Below is my code <?php function upload_user_file( $file = array() ) { require_once( ABSPATH . […]

Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter

I’m retroactively creating a post with wp_insert_post() and attaching a featuring image to it. I need the image to go into the folder that corresponds to the post’s publishing date. I’m using time parameter in wp_handle_upload function that supposed to move files to the directories according to the parameter value (see in the code – […]

Upload video in custom folder

I am trying to find a system to upload some kind of media in a custom folder. I want to keep all uploads in default wordpress folder and create a custom folder just for videos. So i would have the following folder structure: – wp-content – uploads – year – month – videos – category-one […]

Frontend image uploading from frontend cant handle hebrew names

i’m using the insert_attachment code in my functions.php : function insert_attachment($file_handler,$post_id,$setthumb=’false’) { // check to make sure its a successful upload if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $attach_id = media_handle_upload( $file_handler, $post_id ); if ($setthumb) update_post_meta($post_id,’_thumbnail_id’,$attach_id); return $attach_id; } and build […]