문제는 Joomla 파일 필드가 더 이상 아무것도 아니지만 파일을 선택하기위한 양식 필드를 생성하는 것입니다. 즉, 양식 제출시 파일 제출 서버 측을 처리하기 위해 코어에 논리가 내장되어 있지 않습니다. 요청에서 정보를 가져 와서 필요한 곳에 저장하려면 구성 요소 컨트롤러에 논리를 추가해야합니다. 파일 업로드가 필요한 프로젝트 컨트롤러에서 샘플 메서드를 붙여 넣었습니다.
public function upload() {
//JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$jinput = JFactory::getApplication()->input;
jimport('joomla.filesystem.file');
// We're putting all our files in a directory called images.
$path = 'images/uploaded/';
// The posted data, for reference
$file = $jinput->get('value', '', 'string');
$name = $jinput->get('name', '', 'string');
// Get the mime
$getMime = explode('.', $name);
$mime = end($getMime);
// Separate out the data
$data = explode(',', $file);
echo "<h1>" . $path . $name . "</h1>";
// Encode it correctly
$encodedData = str_replace(' ','+',$data[1]);
$decodedData = base64_decode($encodedData);
//if (JFile::upload($decodedData, $path . $name)) {
if(file_put_contents($path . $name, $decodedData)) {
JError::raiseNotice(null, $name . ": uploaded successfully");
} else {
// Show an error message should something go wrong.
JError::raiseError(null, "Something went wrong. Check that the file isn't corrupted");
}
}
이미 서버 측 파일 업로드 컨트롤러 메소드를 작성했습니다 당신이 모든 다른 제안은 문제가되지 않습니다 확인한 경우 기회는 오류가 어디 그건 한, 당신은 당신의 질문의 코드를 포함해야한다 발생합니다.
흠. 이상합니다. 'image/*'를 추가하면 탐색 할 때 파일이 표시되지 않고 폴더 만 – Lodder
나를 위해 모든 이미지 파일이 표시되지만 업로드는 제한됩니다. 기묘한. 백엔드와 프론트 엔드 둘 다. – user1876234
파일을 관리하는 데 사용중인 PHP를 보여 주시겠습니까? 이것으로 인해 발생할 수 있습니다. PHP를 관리 할 PHP가 없다면 제공 한 XML 코드가 양식 필드를 표시하는 것 외에는 아무 것도하지 않기 때문에 수행하십시오. – Lodder