我正在使用这个媒体上传程序wp代码段,它可以将图像从我的一个站点下载到另一个站点。直到昨天它还可以正常工作,但今天早上我检查了一下,它不工作了。
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
出于调试目的,我在某些点回显了值,以了解它在哪里不起作用。我已经检查了php。多次使用ini文件,没有任何更改。以下是错误:
[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"]
前端上传视频:
从前端上载图像时出错:
[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"]
这两行在错误日志中以不同的计时冗余出现。
请任何人建议如何解决这个问题?谢谢