Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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: image 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.

share|improve this question
    
Do you have debugging information? What is in the server logs? Have you used up all your storage space on the server? –  s_ha_dum Sep 1 '13 at 15:15
    
Updated question with errors –  busyjax Sep 1 '13 at 15:45
    
This seems to be related to mod_security, an Apache server module, not to WordPress. See: google.com/search?q=ModSecurity%3A+Error+reading+request+body –  s_ha_dum Sep 1 '13 at 16:08
    
I have tried many things, unchecked this mod_security option, installed wordpress again but still this problem persists. –  busyjax Sep 1 '13 at 20:51
    
I definitely know that there is no problem in above code becoz the same unchanged is working fine on my localhost. But problematic on webhost. –  busyjax Sep 1 '13 at 20:56
show 3 more comments

1 Answer

For those having similar problem, I cleared web-server's /tmp partition being filled with temp files. The root cause was actually that my hosting provider sets the /tmp partition to be 128MB when on their VPS, which is far too small for the size of uploads that I want to be able to do.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.