I am using this media uploader wp snippet which downloads an image from my one site to other. It was working fine until yesterday but I checked this morning, it wasn’t working.
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
$media_img_url="http://abc123.com/wp-content/2013/08/qwerty.jpg";
$tmp = download_url( $media_img_url );
$post_id = 32454;
$desc="The image is here";
echo $tmp; //Output: /tmp/qwerty.tmp
// Set variables for storage
// fix file filename for query strings
preg_match('/[^\?]+\. (jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $media_img_url, $matches);
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
print_r($matches); //Output: Array()
echo $file_array['name']. //Output: Nothing
'<br>'.$file_array['tmp_name']; //Output: /tmp/qwerty.tmp
// If error storing temporarily, unlink
if ( is_wp_error( $tmp ) ) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
echo $file_array['name']; //Output: Nothing
// do the validation and storage stuff
$id = media_handle_sideload( $file_array, $post_id, $desc );
print_r($id); //Output: WP_Error Object ( [errors] => Array ( [upload_error] => Array ( [0] => File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini. ) ) [error_data] => Array ( ) )
// If error storing permanently, unlink
if ( is_wp_error($id) ) {
@unlink($file_array['tmp_name']);
return $id;
}
print_r($id); //Output: Nothing
$src = wp_get_attachment_url( $id );
print_r($src); //Output: Nothing
For debugging purposes, I echoed values at some points to know where it is not working. I have checked php.ini file many times,nothing is changed.
Here are errors:
[Sun Sep 01 07:06:46 2013] [error] [client 213.236.00.15] (70014)End of file found: Error reading request entity data
[Sun Sep 01 07:11:09 2013] [error] [client 213.236.00.15] ModSecurity: Error reading request body: End of file found [hostname "abc123.com"] [uri "/wp-admin/admin-ajax.php"] [unique_id "UiNK-dBhnx0AAA3rD4cAAAAC"]
Frontend uploading Visual:
Error when uploading images from frontend:
[Sun Sep 01 22:54:18 2013] [error] [client 213.236.00.15] ModSecurity: Input filter: Failed writing 8192 bytes to temporary file (rc 18446744073709551615). [hostname "abc123.com"] [uri "/wp-admin/async-upload.php"] [unique_id "UiQoCdBhnx0AACtXBFwAAAAA"]
[Sun Sep 01 22:54:55 2013] [error] [client 213.236.00.15] ModSecurity: Multipart parsing error: Multipart: writing to "/tmp/20130901-225455-UiQoL9Bhnx0AACtYB4gAAAAD-file-pwzC5a" failed [hostname "abc123.com"] [uri "/wp-admin/async-upload.php"] [unique_id "UiQoL9Bhnx0AACtYB4gAAAAD"]
These two lines are present redundantly with different timings in error log.
Please anyone suggest how to resolve this?
Thanks.