2017-12-29 20 views
0

사용자가 이미지를 업로드하여 페이지에 표시 할 수있게하려고합니다.October Cms - 프론트 엔드 양식을 사용하여 png 이미지를 저장하려면 어떻게해야합니까?

다른 방법으로 시도했지만 업로드 작업을 수행하지 못했습니다.

+1

시도해 본 내용의 샘플을 제공해 줄 수 있습니까? –

+0

[php upload image] (https://stackoverflow.com/questions/13465929/php-upload-image)의 가능한 복제본 –

답변

1

먼저 아약스 API를 사용하여 파일 업로드를 지원하므로 10 월 CMS의 최신 빌드가 필요합니다.

{{ form_ajax('onUploadImage', { files: 'true', flash: 'true', 'data-request-files':true, 'data-request-validate': true }) }} 
    <input type="file" name="avatar" id="avatar" /> 
    <button type="submit" data-attach-loading>Upload</button> 
{{ form_close() }} 

파일 : '사실'이 필요합니다. 지금

당신의 component 또는 당신은 당신의 모델은 당신이 당신이 필요로하는 경우 AJAX를 사용하여 파일을 업로드 할 수

public $attachOne = [ 
    'fileRelation' => 'System\Models\File' 
]; 

관련하여 추가 할 수 있습니다 안에는 코드

public function onUploadImage() { 
    // Returns the signed in user 
    $user = Auth::getUser(); 
    $user->avatar = \Input::file('avatar'); 
    $user->save(); 

    //this \Input::file('avatar'); do have file instance 
    so with your model you can also do same 
    // $yourModel get your model instance 
    $yourModel->fileRelation = \Input::file('file_input_name'); 
    $yourModel->save(); 
} 

을 쓸 수 page code section에 파일을 업로드하는 방법 POST 의견을주십시오.