1

My plugin always creates uploads of 4.1KB but these movies should be actually much larger.

First I'm registering them as a shutdown function

register_shutdown_function(array($this, 'downloadVideomailToMediaLibrary'), $videomail);

and here is the implementation of this function

public function downloadVideomailToMediaLibrary($videomail) {
    if ($videomail['webm']) {
      $videoUrl = $videomail['webm'];
    } else if ($videomail['mp4']) {
      $videoUrl = $videomail['mp4'];
    }

    if ($videoUrl) {
      $tempFile = download_url($videoUrl, 300);

      if (is_wp_error($tempFile)) {
        @unlink($tempFile);
        return $tempFile;
      } else {
        // Need to require these files
        if (!function_exists('media_handle_upload')) {
          require_once(ABSPATH . "wp-admin" . '/includes/image.php');
          require_once(ABSPATH . "wp-admin" . '/includes/file.php');
          require_once(ABSPATH . "wp-admin" . '/includes/media.php');
        }

        $videoType = $videomail['recordingStats']['videoType'];
        $subject = 'some subject'

        // Array based on $_FILE as seen in PHP file uploads
        $file = array(
          'name' => $subject . '.' . $videoType,
          'type' => wp_check_filetype($tempFile),
          'tmp_name' => $tempFile,
          'error' => 0,
          'size' => filesize($tempFile),
        );

        // Move the temporary file into the uploads directory
        // https://codex.wordpress.org/Function_Reference/media_handle_sideload
        $results = media_handle_sideload($file, 0, $subject);

        // If error storing permanently, unlink
        if (is_wp_error($results)) {
          @unlink($tempFile);
          return $results;
        }
      }
    }
  }

It works well when run for first time (like 3 MB). But then all subsequent uploads always produce 4.1KB files in the uploads folder.

Maybe there is a bug in the above code or this is a known issue?

1
  • By the way symlinks are always 4.1K ... so it could be that this code, PHP stuff or WordPress is unable to follow symlinks? Commented Jul 17, 2018 at 3:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.