IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   PHP (https://www.ircforumlari.net/php/)
-   -   Basit PHP Upload Fonksiyonu (https://www.ircforumlari.net/php/624427-basit-php-upload-fonksiyonu.html)

hAte 08 Ekim 2014 08:02

Basit PHP Upload Fonksiyonu
 
PHP- Kodu:

<?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- Kodu:

<?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.


Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 15:24.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2025 IRCForumlari.Net Sparhawk