08 Ekim 2014, 08:02
#1 Çevrimdışı
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
Basit PHP Upload Fonksiyonu
PHP Kod: Kodu kopyalamak için üzerine çift tıklayın!
<?php
/**
* upload()
*
* [MENTION=81769]para[/MENTION]m $_FILES fileField
* [MENTION=81769]para[/MENTION]m array $allowedTypes
* [MENTION=81769]para[/MENTION]m int $maxFileSize
* [MENTION=81769]para[/MENTION]m string $uploadDir
* [MENTION=81769]para[/MENTION]m string $newFileName
* [MENTION=27818]return[/MENTION] array
* [MENTION=21475]AuthoR[/MENTION] Yunus Oksuz yunus[MENTION=13041]yunus[/MENTION]oksuz.com
*/
function upload ( $fileField , Array $allowedTypes , $maxFileSize , $uploadDir , $newFileName )
{
function getExtension ( $filename )
{
$filename = explode ( '.' , $filename );
return end ( $filename );
}
function byte2mb ( $byte )
{
return ( $byte / 1024 ) / 1024 ;
}
$types = implode ( '|' , $allowedTypes );
if(! preg_match ( '/(' . $types . ')/' , $fileField [ 'name' ]))
{
return array( 'status' => false , 'file' => '' , 'reason' => 'Yuklenen Dosya Izin Verilen Uzantilarin Disinda' );
}
if( byte2mb ( $fileField [ 'size' ]) > $maxFileSize )
{
return array( 'status' => false , 'file' => '' , 'reason' => 'Izin Verilen Max Dosya Boyunu Astiniz' );
}
if( substr ( $uploadDir , - 1 ) == DIRECTORY_SEPARATOR )
{
// do not anything;
}
else
{
$uploadDir = $uploadDir . DIRECTORY_SEPARATOR ;
}
if(! is_dir ( $uploadDir ))
{
if(! mkdir ( $uploadDir ))
{
return array( 'status' => false , 'file' => '' , 'reason' => $uploadDir . ' klasoru olusturulamiyor olusturup chmod 0777 verin' );
}
else
{
[ MENTION = 17451 ] Chmod [/ MENTION ]( $uploadDir , 0777 );
}
}
$ext = getExtension ( $fileField [ 'name' ]);
if(@ move_uploaded_file ( $fileField [ 'tmp_name' ], $uploadDir . $newFileName . '.' . $ext ))
{
return array( 'status' => true , 'file' => $uploadDir . $newFileName . '.' . $ext , 'reason' => '' );
}
else
{
return array( 'status' => false , 'file' => '' , 'reason' => 'Dosya Yuklemesi Gerceklesmedi. Dizinin (' . $uploadDir . ') Yazilabilir Olduguna Emin Olun.' );
}
}
?>
Örnek ;
PHP Kod: Kodu kopyalamak için üzerine çift tıklayın!
<?php require_once( 'func_upload.php' ); if(isset( $_POST [ 'submit' ])){ $up = upload ( $_FILES [ 'fileField' ],array( 'gif' , 'png' , 'jpeg' , 'jpg' ), 5 , 'upload' , rand ( 0 , 9999999 )); if( $up [ 'status' ] === false ) echo $up [ 'reason' ] else echo $up [ 'file' ]; } ?> <!--- HTML Yükleme Formu ---> <form action="" method="post" enctype="multipart/form-data" /> <input type="file" name="fileField" /> <input type="submit" value="gonder" name="submit">
Alıntıdır.
__________________
Bu kez pek bir afili yalnızlık, ağlatan bir kadın kadar düşman. Ağzı bozuk üstelik bırakmıyor acıtmadan.