Im trying to creating my own custom image/file uploader on the front-end of my WordPress site. When I upload a file it gets to my database just fine but in the Media Library the file doesn't upload fully and when I check my wp-content/uploads folder nothing is there how do I correct this.
Image of file in Media Library unfinished upload file in Media Library
<form method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="img-upload" id="img-upload" />
<input type="submit" value="Upload Image" name="submit">
</form>
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$image = $_POST['img-upload'];
$upload_dir = wp_upload_dir();
$file_name = basename($image);
//$file_data = file_get_contents($file);
$file_dir = $upload_dir['basedir'] . "/" . basename($image);
$file_type = wp_check_filetype($image,null);
$attachment = array(
'guid' => $file_dir,
'post_mime_type' => $file_type['type'],
'post_title' => preg_replace('/\\.[^.\\s]{3,4}$/', '', $image),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $image,0 );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata($attach_id, $file_dir);
wp_update_attachment_metadata($attach_id, $attach_data);
print_r($_FILES);
? – user2914191$_FILES
. stackoverflow.com/questions/3586919/… and just so youre aware,$_FILES
should only contain data when you submit a form and upload a file. – user2914191