Dosya gönder işlemi biraz karşık, sayılır. Dokumanlarda anlayamadığın ya da takıldığın bir yer varsa o kısmı yazabilirsin. Bir projemden örnek bir method.
Bu method controller içinde kullanıldı..
/**
* To move uploaded file to the app's directory.
*
* To know target directory, look at ../app/config/upload.php
*
* @return \Symfony\Component\HttpFoundation\File
* @throws \RuntimeException
*/
private function moveUploadedFile() {
$uploadedFile = $this->request->file('file');
$extension = $uploadedFile->getClientOriginalExtension();
$name = $this->getUniqueFileName($extension);
$size = $uploadedFile->getSize();
// we must to save uploaded file's information before it is moved !!!
$this->saveOrginalFileInfo($uploadedFile);
$movedFile = $this->request->file('file')->move($this->getDirectoryPathForUploading(), $name . '.' . $extension);
if ($movedFile->getSize() === $size) {
return $movedFile;
}
throw new \RuntimeException('It looks uploaded file was moved unsucceed. '
. 'Uploaded file size is not equal to moved file size!');
}
Yukarıdaki method sunucuya gönderilen dosyayı benzersiz bir isimle sunucuya kayıt ediyor..