2014-02-10 11 views
0

wordpress의 맞춤 PHP 플러그인에 로고 업로드 기능을 추가해야합니다. 나는이에 파일을 제출하는 경우 그것은 나에게 다음과 같은 오류를 제공Wordpress 업로드 기능을 사용하여 파일을 업로드 할 수 없습니다.

<form action="' . site_url('/edit-company/?cid=' . $_GET['cid']) . '" method="post"> 
               <label><b>Company Name:</b></label> <input type="text" name="editname" value="' . $company->company_name . '"> 
               <label><b>Address:</b></label> <input type="text" name="editaddress" value="' . $company->company_address . '"> 
               <label><b>Telephone:</b></label> <input type="text" name="edittelephone" value="' . $company->company_telephone . '"> 
               <label><b>Fax:</b></label> <input type="text" name="editfax" value="' . $company->company_fax . '"> 
               <label><b>Email:</b></label> <input type="text" name="editemail" value="' . $company->company_email . '"> 
               <label><b>Website:</b></label> <input type="text" name="editwebsite" value="' . $company->company_website . '"> 
               <label><b>Logo:</b></label> <input type="file" name="editfile" id="file"> 
               <input type="submit" value="Submit"> 
              </form> 

: 나는 워드 프레스 사본에이 코드를 발견 : 여기

if (! function_exists('wp_handle_upload')) require_once(ABSPATH . 'wp-admin/includes/file.php'); 
$uploadedfile = $_FILES['editfile']; 
$upload_overrides = array('test_form' => false); 
$movefile = wp_handle_upload($uploadedfile, $upload_overrides); 
if ($movefile) { 
    echo "File is valid, and was successfully uploaded.\n"; 
    var_dump($movefile); 
} else { 
    echo "Possible file upload attack!\n"; 
} 

양식입니다

File is valid, and was successfully uploaded. array(1) { ["error"]=> string(212) "File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini." }

제출할 파일 크기는 약 50kb입니다. 더 크거나 작은 파일을 업로드하는 것은 효과가있는 것 같지 않습니다.

WordPress admin에서 어떤 크기의 파일을 업로드해도 문제가 없습니다. php.ini 또는 최대 크기를 게시하는 것이이 문제의 원인이라고 생각하지 않습니까?

여기에 대한 정보 나 조언이 있으면 알려 주시기 바랍니다. 나는 꽤 오랫동안 이것에 붙어 있었다. vanilla PHP에서 간단한 업로드 스크립트를 사용해 보았습니다.하지만 작동하지 않는 것 같아서 wp 함수로 끝내려고합니다.

UPDATE : 는 - 777에 업로드 폴더의 사용 권한을 설정하지 시도 - 더 도움

+1

양식의 속성이 추가하십시오 . –

+0

wp uploads 폴더의 권한을 775로 설정하는 것이 안전합니까? –

+1

예 775 권한을 설정하는 것이 안전합니다. –

답변

3

을 업로드 형태가 다른 형태의 내부에 있지 않은지 확인하십시오. 왜냐하면 일단 내가 당신과 같은 오류를 겪었고 문제는 내 업로드 양식이 다른 양식 안에 있기 때문입니다.

희망이 도움이 될 수 있습니다.

[업데이트]

양식은 괜찮지 만, 난 당신이 잡을 입력 필드 이름과 포스트 변수 이름은 그 이름이 다를 수 안

$uploadedfile = $_FILES['file']; 

<input type="file" name="editfile" id="file"> 

다른 것을 알 수있다. 이

$uploadedfile = $_FILES['editfile']; 

[업데이트]

처럼 편집하려고 또한 당신이 당신이 파일을 업로드하려고 폴더에 권한을 필요가 있다고 생각

enctype="multipart/form-data" 
+0

원래 질문을 양식 코드로 업데이트했습니다. 나에게 그것은 모두 괜찮은 것 같다. –

+0

고마워요.하지만 그건 편집되지 않은 예제 코드를 복사하는 것 뿐이지요. 실제 사용하는 수정 된 코드는 아니며, 'editfile'이라는 이름이 같습니다. 이 사실을 알지 못해 죄송합니다. –

+1

다음 번에는 실제 코드를 복사하여 피해주십시오. :) btw, 다른 입력란은 어떨까요? ?? 제대로 작동합니까 .. ?? – yogipriyo

관련 문제