Articles of wp handle upload

Rename image during upload using date and time stamp?

I am trying to rename images during upload to avoid problems with image file names containig special characters and file names with non-latin characters. I found this function to rename images in WordPress: function sanitize_file_uploads( $file ){ $file[‘name’] = sanitize_file_name($file[‘name’]); $file[‘name’] = preg_replace(“/[^a-zA-Z0-9\_\-\.]/”, “”, $file[‘name’]); $file[‘name’] = strtolower($file[‘name’]); add_filter(‘sanitize_file_name’, ‘remove_accents’); return $file; } add_filter(‘wp_handle_upload_prefilter’, ‘sanitize_file_uploads’); […]

how to upload image using wp_handle_upload

hi i am new on WordPress can somebody tell me how can i upload multiple images using wp_handle_upload in a loop for($i=1;$i<count($_FILES[‘myfile’][‘name’]);$i++){ $uploadedfile = $_FILES[‘myfile’].$i; $upload_overrides = array( ‘test_form’.$i => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if ( $movefile && !isset( $movefile[‘error’] ) ) { // echo “File is valid, and was successfully […]

How to upload multiple images on frontend to ACF gallery using update_field

I’m trying to save images submitted on a frontend form in a way that they are accessible via the ACF backend. In how to upload an image on ACF with update_field on wordpress, someone provided a solution for a single image upload (and consequently a single ACF image field). I thought it should be pretty […]

wp_handle_upload – The uploaded file could not be moved to wp-content/uploads/2012/09

This is the code I am using to upload the file to WordPress define(‘WP_DEBUG’, true); $filename = “test.png”; $tmpFile = download_url(“http://url.com/testing/crop/”.$filename); chmod($tmpFile, 0755); $mimeType = wp_check_filetype($_SERVER[‘DOCUMENT_ROOT’] . ‘/testing/crop/’.$filename); $file_array = array( ‘file’ => $_SERVER[‘DOCUMENT_ROOT’] . ‘/testing/crop/’.$filename, ‘url’ => $_SERVER[‘DOCUMENT_ROOT’] . ‘/testing/crop/’.$filename, ‘type’ => $mimeType[‘type’], ‘size’ => filesize($_SERVER[‘DOCUMENT_ROOT’] . ‘/testing/crop/’.$filename), ‘name’ => $filename, ‘tmp_name’ => $tmpFile […]

Custom image upload

I’m trying to setup upload for for attachments for my custom post form. At first I add to my form tag enctype=”multipart/form-data” For testing purposes I have two upload forms, but in future I’m gonna implement only one form and use jQuery to append as many forms as I want. <fieldset class=”images”> <label for=”images”>Front of […]

rename attachments based on parent-post-title on upload

I know there a some functions already avaible here for this task, but none of them seem to work as needed. The best way seems to me adding a filter to wp_handle_upload_prefilter like kaiser does in this example. Unfortunately the file only gets the parent-post-title if the post is already saved to the database. Another […]

capability for upload on front-end (An error occurred in the upload. Please try again later )

We have a front-end form with wp-editor on front-end template page. Everything is working fine. but the only problem is “we can’t add new images on front end form”. there is an error “An error occurred in the upload. Please try again later” This front end shows only the author own files. // Show only […]

How to resize image on client-side before upload?

I’ve been using Plupload to resize images on the client side before uploading them to the server. I’ve implemented a front-end form which lets the user select a file from their computer and submit it. My Plupload config looks like this: var uploader = new plupload.Uploader({ browse_button: ‘browse’, url: $url, resize: { width: 100, height: […]

Disable drag and upload in Media Library

Does any one knows a valid/standard way to disable drag and upload when accessing the media library in the admin area? In order to make this sense to you, I’m building a multisite and user of sub-site cannot upload media files but they can view. I can remove their capability ‘upload_file’ but that would completely […]

How to upload image from front end and save in media library?

I am working on a plugin .I want to upload image from front end i.e by input type=”file”.I did lot of google for it but could not upload image .Here is my code for uploading image <form method=”post” action=”options.php”> <input type=”file” name=”my_image_upload” id=”my_image_upload” multiple=”false” /> <input type=”hidden” name=”post_id” id=”post_id” value=”55″ /> <?php wp_nonce_field( ‘my_image_upload’, ‘my_image_upload_nonce’ […]