나는 다양한 방법으로 파일을 WordPress 사이트 업로드 디렉토리에 업로드하려고 시도해 왔습니다. 현재 권한 문제가 발생하지 않도록 777 권한을 부여했습니다. 코드가있는 사용자 정의 PHP 플러그인이 있습니다.PHP 스크립트로 파일을 업로드 할 때 잘못된 파일 오류가 발생했습니다.
나는 워드 프레스 기능을 사용해 보았지만 작동하지 않는 것 같습니다.
이제 파일 업로드 (양식 제출)를 처리해야하는 PHP 코드 조각이 있습니다.
여기 내 처리 코드입니다 :
//image upload handling
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["editfile"]["name"]);
$extension = end($temp);
if ((($_FILES["editfile"]["type"] == "image/gif")
|| ($_FILES["editfile"]["type"] == "image/jpeg")
|| ($_FILES["editfile"]["type"] == "image/jpg")
|| ($_FILES["editfile"]["type"] == "image/pjpeg")
|| ($_FILES["editfile"]["type"] == "image/x-png")
|| ($_FILES["editfile"]["type"] == "image/png"))
&& ($_FILES["editfile"]["size"] < 5000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["editfile"]["error"] > 0)
{
$tim_core_edit_company_page .= "Return Code: " . $_FILES["editfile"]["error"] . "<br>";
}
else
{
$tim_core_edit_company_page .= "Upload: " . $_FILES["editfile"]["name"] . "<br>";
$tim_core_edit_company_page .= "Type: " . $_FILES["editfile"]["type"] . "<br>";
$tim_core_edit_company_page .= "Size: " . ($_FILES["editfile"]["size"]/1024) . " kB<br>";
$tim_core_edit_company_page .= "Temp file: " . $_FILES["editfile"]["tmp_name"] . "<br>";
if (file_exists(wp_upload_dir() . $_FILES["editfile"]["name"]))
{
$tim_core_edit_company_page .= $_FILES["editfile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["editfile"]["tmp_name"],
"upload/" . $_FILES["editfile"]["name"]);
$tim_core_edit_company_page .= "Stored in: " . "upload/" . $_FILES["editfile"]["name"];
}
}
}
else
{
$tim_core_edit_company_page .= "Invalid file";
}
그리고 여기에 파일을 제출하는 데 사용되는 형태이다 :
<form action="' . site_url('/edit-company/?cid=' . $_GET['cid']
. '&lid=' . $_GET['lid']
. '&cname=' . $_GET['cname'] . '&editcompany=1&todb=1') . '" 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>
내가 얻을 응답은 "잘못된 파일"입니다. 나는 모든 종류의 이미지를 업로드하는 것에 지쳤으며 결과는 항상 동일합니다.
누가이 문제의 원인인지 알 수 있습니까?
업데이트 :
나는 양식에 enctype = "다중/폼 데이터를"추가 조언을 따라 분명히 잘못된 파일 오류는 이제 사라졌다. 그러나 wp-content/uploads 디렉토리에 아직 업로드가 표시되지 않습니다. 스크립트가 어떻게 든 변경되었지만 실제 업로드 된 파일은 어디에도 표시되지 않습니다. 나는 그것이 업로드 디렉토리를 처리하는 워드 프레스와 관련이있을 것이라고 생각한다.
양식 태그에 속성 enctype = "multipart/form-data"를 추가하십시오. – PravinS