我在最近维护的一个网站上,这个功能已经停止工作了,我不知道确切的原因。第一个media\\u handle\\u upload功能失败,出现以下错误:
Array([error] => Specified file failed upload test.
尝试使用此代码而不是media\\u handle\\u upload,
https://gist.github.com/hissy/7352933 , 但在使用gist中的代码时,我发现了一个错误:
017/05/17 05:45:59 [error] 2066#2066: *10499 FastCGI sent in stderr: "PHP message: PHP Warning: file_get_contents(/tmp/php8mjcrC): failed to open stream: No such file or directory in /srv/www/test.dev/current/web/app/themes/test/functions.php on line 1083
这是我的功能。它连接到一个重力表单表单,该表单接受用户提交的照片。我想在媒体库中自动填充这些内容。它过去很管用,我不知道是什么破坏了它,可能是WordPress v4中的某些东西。7.
add_action("gform_pre_submission_16", "post_submission");
function post_submission(){
$body = \'From: \'.$_POST[\'input_2\'];
$body .= \'<br/>Email: \'.$_POST[\'input_3\'];
$body .= \'<br/>Description: \'.$_POST[\'input_5\'];
$mypostID = 0; // change it to your desired post id
$photo_description = $_POST[\'input_5\'];
$photo_credit = $_POST[\'input_2\'];
if( !empty($_FILES[\'input_13\'][\'name\'])) {
require_once(ABSPATH . \'wp-admin/includes/file.php\');
require_once(ABSPATH . \'wp-admin/includes/image.php\');
require_once(ABSPATH . \'wp-admin/includes/media.php\');
$attach_id = media_handle_upload(\'input_13\', $mypostID);
$strain_cat_id = $_POST[\'input_20\'];
$cat_id = $_POST[\'input_21\'];
wp_set_object_terms( $attach_id, $strain_cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, $cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, 170, \'media_category\', true );
$my_post = array(
\'ID\' => $attach_id,
\'post_content\' => $photo_description
);
wp_update_post( $my_post );
update_post_meta( $attach_id, \'photo_credit\', $photo_credit );
$body .= \'<br/><a href="http://darkheartnursery.com/wp-admin/upload.php?item=\'.$attach_id.\'">View Photo for \'.$strain_cat_id.\'</a>\';
}
if( !empty($_FILES[\'input_14\'][\'name\']) ) {
$attach_id = media_handle_upload(\'input_14\', $mypostID);
$strain_cat_id = $_POST[\'input_22\'];
$cat_id = $_POST[\'input_26\'];
wp_set_object_terms( $attach_id, $strain_cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, $cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, 170, \'media_category\', true );
$my_post = array(
\'ID\' => $attach_id,
\'post_content\' => $photo_description
);
wp_update_post( $my_post );
update_post_meta( $attach_id, \'photo_credit\', $photo_credit );
$body .= \'<br/><a href="http://darkheartnursery.com/wp-admin/upload.php?item=\'.$attach_id.\'">View Photo for \'.$strain_cat_id.\'</a>\';
}
if( !empty($_FILES[\'input_15\'][\'name\']) ) {
$attach_id = media_handle_upload(\'input_15\', $mypostID);
$strain_cat_id = $_POST[\'input_23\'];
$cat_id = $_POST[\'input_27\'];
wp_set_object_terms( $attach_id, $strain_cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, $cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, 170, \'media_category\', true );
$my_post = array(
\'ID\' => $attach_id,
\'post_content\' => $photo_description
);
wp_update_post( $my_post );
update_post_meta( $attach_id, \'photo_credit\', $photo_credit );
$body .= \'<br/><a href="http://darkheartnursery.com/wp-admin/upload.php?item=\'.$attach_id.\'">View Photo for \'.$strain_cat_id.\'</a>\';
}
if( !empty($_FILES[\'input_16\'][\'name\']) ) {
$attach_id = media_handle_upload(\'input_16\', $mypostID);
$strain_cat_id = $_POST[\'input_24\'];
$cat_id = $_POST[\'input_28\'];
wp_set_object_terms( $attach_id, $strain_cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, $cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, 170, \'media_category\', true );
$my_post = array(
\'ID\' => $attach_id,
\'post_content\' => $photo_description
);
wp_update_post( $my_post );
update_post_meta( $attach_id, \'photo_credit\', $photo_credit );
$body .= \'<br/><a href="http://darkheartnursery.com/wp-admin/upload.php?item=\'.$attach_id.\'">View Photo for \'.$strain_cat_id.\'</a>\';
}
if( !empty($_FILES[\'input_17\'][\'name\']) ) {
$attach_id = media_handle_upload(\'input_17\', $mypostID);
$strain_cat_id = $_POST[\'input_25\'];
$cat_id = $_POST[\'input_29\'];
wp_set_object_terms( $attach_id, $strain_cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, $cat_id, \'media_category\', true );
wp_set_object_terms( $attach_id, 170, \'media_category\', true );
$my_post = array(
\'ID\' => $attach_id,
\'post_content\' => $photo_description
);
wp_update_post( $my_post );
update_post_meta( $attach_id, \'photo_credit\', $photo_credit );
}
}
非常感谢您在这方面的帮助或指导。如果需要,我也可以提供更清晰的信息或代码。谢谢