2014-09-11 2 views
0

양식이 있습니다. 제출 버튼을 누르면 이미지가 업로드되지만 미디어 라이브러리에는 표시되지 않습니다.양식에서 미디어 라이브러리 wordpress에 업로드 된 이미지를 추가하는 방법?

양식의 이미지를 미디어 라이브러리에 어떻게 추가합니까?

HTML을

<form method="post" enctype="multipart/form-data"> 
<input type='file' name='file'> 
<input type='submit' value='send'> 
</form> 

워드 프레스

if (!function_exists('wp_handle_upload')) { 
require_once(ABSPATH . 'wp-admin/includes/file.php'); } 

$uploaded_file = $_FILES['file']; 

upload_overrides = array('test_form' => false); 

$file = wp_handle_upload($uploaded_file,$upload_overrides); 

if ($file) { 
echo "File is valid and was successfully uploaded"; 
var_dump($file); 
} else { 
echo "Possible file upload attack"; 
} 

나는 연구를하고 http://codex.wordpress.org/Function_Reference/wp_insert_attachment의 코드가 작동하지 않습니다.

제대로 작동하려면 wp_insert_attachment()가 필요합니다. 고맙습니다.

replace var_dump($movefile); with var_dump($file); 

당신이 $ 파일 변수와 인쇄 $를 사용하는

답변

0

대신 media_handle_upload()을 확인 할 수 있습니다를 제공 할 것입니다 생각합니다.

$return = media_handle_upload('file', 0); 

if (is_int($return)) { 
    echo "File is valid and was successfully uploaded. New ID: $return"; 
} else { 
    var_dump($return); 
} 
+0

감사합니다. 이것이 해결책입니다. –

0

주 movefile.So하시기 바랍니다 내가 당신에게 도움이

+0

귀하의 권리. 그 오류를 해결할 것입니다. 하지만 이미지를 미디어 라이브러리에 추가하지는 않습니다. –

관련 문제