Skip to content

Instantly share code, notes, and snippets.

@taner-dll
Last active December 16, 2019 03:06
Show Gist options
  • Save taner-dll/6474281 to your computer and use it in GitHub Desktop.
Save taner-dll/6474281 to your computer and use it in GitHub Desktop.
Symfony 2 - Basic Image Upload
$file = $_FILES['fileinput'];
$this->SF2imageUpload($file['name'],$file['type'],$file['size'],$file['error'],$file['tmp_name'],$upload_directory);
public function SF2imageUpload($file, $file_type, $file_size, $file_error, $temp, $upload_url)
{
//Kabul edilen uzantılar.
$allowed_extensions = array("gif", "jpeg", "jpg", "png");
//Kabul edilen imaj tipleri.
$allowed_images = array("image/jpeg", "image/jpg", "image/gif", "image/png");
//Dosya uzantisini al.
$file_name = explode(".", $file);
$file_ext = end($file_name);
//Dosya tipi kontrolü.
if(in_array($file_ext, $allowed_extensions) && in_array($file_type, $allowed_images) && $file_size < 20000)
{
if($file_error > 0)
{
throw $this->createNotFoundException('Hata Kodu: '.$file_error);
}
elseif(file_exists($upload_url.$file))
{
throw $this->createNotFoundException('Bu isimde resim zaten mevcut.');
}
else
{
move_uploaded_file($temp,$upload_url.$file);
}
}
else
{
throw $this->createNotFoundException('Geçersiz dosya.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment