#StackBounty: #php #uploads #pdf PDF file randomly breaks upon upload

Bounty: 100

The issue randomly started happening. When I upload a PDF file via the media library, it sometimes ‘adds’ random lines and graphics to the PDF file(or solid brown color), but sometimes it is okay.
WP core is updated to latest, plugins as well, php is running 7.3.
I wonder if it is ever WordPress issue or a hosting issue.

What could be the reason?

EDIT:
here’s the list of the plugins:

Abandoned Cart Lite for WooCommerce
Advanced Custom Fields PRO
Advanced Order Export For WooCommerce
Contact Form 7
LionScripts: IP Blocker Lite
Mouseflow for WordPress
MultiLine files for Contact Form 7
NotificationX
Post SMTP
Really Simple SSL
SVG Support
WooCommerce
WooCommerce Order Status Control
WooCommerce Order Status Manager
WooCommerce Stripe Gateway
WP Cerber Security, Anti-spam & Malware Scan
WP-PageNavi
Yoast SEO Premium

Which one has a chance to be the problem?

EDIT 2: here’s what the PDF looks like(only one of the pages, other ones are fine actually:
enter image description here

Also, the XHR Request sometimes responds with JSON data, and sometimes the response is empty. This is all RANDOM, very weird bug.

EDIT 3: it’s not from a plugin, I have disabled them all except the acf

EDIT 4: I have found it is not inserting _wp_attachment_metadata in the wp_postmeta table(it works only through media library, but not from the acf file field)


Get this bounty!!!

#StackBounty: #uploads #media #front-end How to change upload directory based on frontend form input name or ID?

Bounty: 50

I created a frontend form using a plugin which allows logged in users to create draft posts. There are 3 file upload areas. I need 1 of them to use the default public WP media upload folder as usual. But I need the files uploaded via 2nd and 3rd file upload areas to move to a restricted sub folder inside the default WordPress file upload folder. 1 of them allow multiple file uploads.

Important facts:

  1. I have changed the default WP_CONTENT folder and UPLOADS folder using wp-config.php
  2. One of the file upload areas allows multiple file uploads

This is the file upload field generated by a custom plugin:
<input type="text" class="multiple_files" data-formid="11" data-fieldname="multiple_files" placeholder="http://" name="files[0]" value="" data-required="yes" data-type="multiple" required="" autocomplete="off">

People can choose to add more, then the name changes to files[1], files[2] , so on..

What I basically need is something like this:

add_filter('wp_handle_upload_prefilter', 'custom_upload_prefilter');
add_filter('wp_handle_upload', 'custom_upload_handle');

function custom_upload_prefilter($file){
    add_filter('upload_dir', 'custom_upload_dir');
    return $file;
}

function custom_upload_handle($fileinfo){
    remove_filter('upload_dir', 'custom_upload_dir');
    return $fileinfo;
}

function custom_upload_dir($path){  
if ( isset( $_REQUEST['files'][0] ) ) {
    $customdir = '/secured'. $path['subdir'];     
        $path['path']   = $path['basedir'] . $customdir;
        $path['url']      = $path['baseurl'] . $customdir;
}
return $path;
}

But $_REQUEST only works when you have submitted the form, not when you upload the files.

I’m new to WordPress. I looked around to find an exact solution to my issue. there are a few solution but I not exactly what I’m looking for. Thank you very much.


Get this bounty!!!

#StackBounty: #uploads #media #thumbnails #svg SVG not displaying in Media Tab in Backend

Bounty: 50

I addes this code to allow SVG Uploads to the Media Library of wordpress:

function upload_svg ( $svg_mime ){
$svg_mime['svg'] = 'image/svg+xml';
return $svg_mime;
}

add_filter( 'upload_mimes', 'upload_svg' );
define('ALLOW_UNFILTERED_UPLOADS', true);

Than I added some SVGs to the Media Library. Using them works perfectly fine. The only Issue I have is that they will not be displayed in the Media Library. On other Pages in the Backend they display fine.

Is there anything I can do to display them in the Media Tab aswell? I couln’t find anything online on how to fix this issue.


Get this bounty!!!

#StackBounty: #custom-post-types #uploads #post-thumbnails #media #pdf Force documents to appear in Featured Image dialogue

Bounty: 50

Having a perplexing issue… …for a custom post-type called ‘Resources’ I used the ‘Featured Image’ or ‘thumbnail’ function within WordPress to allow users to attach documents to ‘Resources’. The process itself works exactly as expected and anticipated.

However, setting the site up, someone made a mistake and uploaded two documents and assigned them to the wrong ‘Resources’. So Resource A -> Document B and Resource B -> Document A.

When attempting to switch them and clicking ‘Edit Featured Image’ you are unable to see any of the documents. They clicked ‘Remove Featured Image’ and then ‘Set Featured Image’ and when the dialogue opens, still no documents.

In the WordPress Media Library all of the uploaded and attached documents are there. Visible, with previews, etc. As expected. Here’s the first two rows of the Media Library. You can see tons of PDFs that have been successfully uploaded.
Media Library

The only place where this issue appears is that in the actual ‘Featured Image’ media dialogue box, WordPress will not display any PDFs.

Here’s the CPT supports segment:

$rsc_supports = array(
     'title',
     'editor',
     'thumbnail',
     'page-attributes'
);

Like I said, everything works perfectly – even uploading and attaching PDFs as ‘thumbnails’ to be associated as attachments with the CPT. When a PDF is attached and you ‘Click to edit’ the dialogue opens up and you can see the attached PDF in the list.
The only failing is that the ‘Featured Image’ modal/pop-up/dialogue box that loads, is designed to filter out everything except images.
This is what that dialogue box looks like on a ‘Resource’ with nothing attached.
Featured Image Dialogue

However, if you view another Resource that does have a PDF already attached, you get this:
With PDF Attached

I have tried the filtering and date dropdown and they don’t address this.

I believe this is by design. So my question is, “How do I modify that dialogue box to display all files rather than just images?”


Get this bounty!!!

#StackBounty: #images #uploads #media-library Why does WordPress convert my jpg's to png?

Bounty: 50

Anytime I upload an image to the media library it shows up as a png. And when I want to use it in a post WordPress tells me I can’t use a png.

How does this happen? The site is in development and running on localhost.

I have changes the .htaccess to allow bigger files to be uploaded. But after deleting these rules nothing changes. Nothing in functions.php about the media library.

How does this happen? Where should I look to troubleshoot this?


Get this bounty!!!

#StackBounty: #images #uploads #media-library Why does WordPress convert my jpg's to png?

Bounty: 50

Anytime I upload an image to the media library it shows up as a png. And when I want to use it in a post WordPress tells me I can’t use a png.

How does this happen? The site is in development and running on localhost.

I have changes the .htaccess to allow bigger files to be uploaded. But after deleting these rules nothing changes. Nothing in functions.php about the media library.

How does this happen? Where should I look to troubleshoot this?


Get this bounty!!!

#StackBounty: #images #uploads #media-library Why does WordPress convert my jpg's to png?

Bounty: 50

Anytime I upload an image to the media library it shows up as a png. And when I want to use it in a post WordPress tells me I can’t use a png.

How does this happen? The site is in development and running on localhost.

I have changes the .htaccess to allow bigger files to be uploaded. But after deleting these rules nothing changes. Nothing in functions.php about the media library.

How does this happen? Where should I look to troubleshoot this?


Get this bounty!!!

#StackBounty: #images #uploads #media-library Why does WordPress convert my jpg's to png?

Bounty: 50

Anytime I upload an image to the media library it shows up as a png. And when I want to use it in a post WordPress tells me I can’t use a png.

How does this happen? The site is in development and running on localhost.

I have changes the .htaccess to allow bigger files to be uploaded. But after deleting these rules nothing changes. Nothing in functions.php about the media library.

How does this happen? Where should I look to troubleshoot this?


Get this bounty!!!

#StackBounty: #images #uploads #media-library Why does WordPress convert my jpg's to png?

Bounty: 50

Anytime I upload an image to the media library it shows up as a png. And when I want to use it in a post WordPress tells me I can’t use a png.

How does this happen? The site is in development and running on localhost.

I have changes the .htaccess to allow bigger files to be uploaded. But after deleting these rules nothing changes. Nothing in functions.php about the media library.

How does this happen? Where should I look to troubleshoot this?


Get this bounty!!!

#StackBounty: #images #uploads #media-library Why does WordPress convert my jpg's to png?

Bounty: 50

Anytime I upload an image to the media library it shows up as a png. And when I want to use it in a post WordPress tells me I can’t use a png.

How does this happen? The site is in development and running on localhost.

I have changes the .htaccess to allow bigger files to be uploaded. But after deleting these rules nothing changes. Nothing in functions.php about the media library.

How does this happen? Where should I look to troubleshoot this?


Get this bounty!!!