In order to do this, we’ll have to edit the upload function in order to incorporate a variable for the type of file being uploaded. The function we’re interested in is wp-admin/admin-functions.php. The function is called wp_handle_upload()
–
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/$filename";
if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) )
die(printf(__('The uploaded file could not be moved to %s.'), file['path']));
and
// Compute the URL
$url = $uploads['url'] . "/$filename";
The easiest thing we can do is add the extension into the upload path. This will mean that JPEGs and PDFs will be stored at something like https://mysite.com/blog/uploads/jpg/ or https://mysite.com/blog/uploads/pdf/, respectively.
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/" . $ext . "/$filename";
if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) )
die(printf(__('The uploaded file could not be moved to %s.'), file['path']));
and
// Compute the URL
$url = $uploads['url'] . "/" . $ext . "/$filename";
If your pathing is something else, you’ll have to put a switch function in there to determine the directory, or however it suits you. Good luck.
[signature moderated Please read the Forum Rules]