v2.5.2
Giriş yap

Dosya Yükleme Sorunu (PHP)

rennie
1,284 defa görüntülendi
<?php
include_once('../config.php');

    
    // klasör oluştur
        $kLasorAdi = uniqid().date("dmY");
        $old = umask(0);
        mkdir("../uploads/".$kLasorAdi, 0777);
        umask($old);
    // klasör oluştur
 
if(!empty($_FILES['files'])){
    $n=0;
    $s=0;
    $prepareNames   =   array();
    foreach($_FILES['files']['name'] as $val)
    {
        $infoExt        =   getimagesize($_FILES['files']['tmp_name'][$n]);
        $s++;
        $filesName      =   str_replace(" ","",trim($_FILES['files']['name'][$n]));
        $files          =   explode(".",$filesName);
        $File_Ext       =   substr($_FILES['files']['name'][$n], strrpos($_FILES['files']['name'][$n],'.'));
         
        if($infoExt['mime'] == 'image/gif' || $infoExt['mime'] == 'image/jpeg' || $infoExt['mime'] == 'image/png' || $infoExt['mime'] == 'image/jpg')
        {
            $srcPath    =   '../uploads/'.$kLasorAdi.'/';
            $fileName   =   $s.rand(0,999).time().$File_Ext;
            $path   =   trim($srcPath.$fileName);
            if(move_uploaded_file($_FILES['files']['tmp_name'][$n], $path))
            {
                $prepareNames[] .=  $fileName; //need to be fixed.
                $Sflag      =   1; // success
            }else{
                $Sflag  = 2; // file not move to the destination
            }
        }
        else
        {
            $Sflag  = 3; //extention not valid
        }
        $n++;
    }
    if($Sflag==1){
        echo '{Images uploaded successfully!}';
    }else if($Sflag==2){
        echo '{File not move to the destination.}';
    }else if($Sflag==3){
        echo '{File extention not good. Try with .PNG, .JPEG, .GIF, .JPG}';
    }
 
    if(!empty($prepareNames)){
        $count  =   1;
        foreach($prepareNames as $name){
            $data   =   array(
                            'img_name'=>$name,
                            'img_order'=>$count++,
                        );
            $db->insert(TB_IMG,$data);
        }
    }
}
?>

PHP ile çoklu resim yükleme üzerine çalışıyorum, ama bir sorun var.
Resimleri yüklerken uzantısı küçük harf ile olursa .jpg, .png gibi belirttiğim klasöre yüklüyor,
ama uzantısı .JPG, .PNG olursa büyük şekilde yüklemiyor, nasıl çözebilirim ?

rennie
1197 gün önce

Bu sefer büyük formatlı dosyaları yüklüyor (PNG,JPG) ama tek tek. Multiple olmuyor. Nerede hata yapıyorum.

<?
 
require 'class.upload.php';
	
$images = array();
foreach ($_FILES['YuklenenResimler'] as $k => $l) {
	foreach ($l as $i => $v) {
		if (!array_key_exists($i, $images))
		$images[$i] = array();
		$images[$i][$k] = $v;
	}
}

	if(isset($_POST["submit"])){
	// klasör oluştur
		$yeniklasor = uniqid();
		$old = umask(0);
		mkdir("portfoy/".$yeniklasor, 0777);
		umask($old);
	// klasör oluştur
	foreach ($images as $image){
		$Atlet = new VerotUploadUpload($image);
		if ($Atlet->uploaded) {
			$Atlet->file_new_name_body = substr(base64_encode(uniqid(true)), 0, 10);			
			$Atlet->image_convert = jpg;
			$Atlet->image_resize = true;
			$Atlet->image_ratio_crop = true;
			$Atlet->image_x = 200;
			$Atlet->image_y = 100;
			$Atlet->allowed = array('image/*');
			$Atlet->Process("portfoy/".$yeniklasor."/");
			if ($Atlet->processed) {
				echo 'ok';
			} else {
				echo $Atlet->error;
			}
				$Atlet-> Clean();
			} else {
				echo $Atlet->error;
			}
		}
	}
?>
<form method="post" action="" enctype="multipart/form-data">
	<input type="file" name="YuklenenResimler[]" multiple />
	<input type="submit" name="submit" value="Yükle" />
</form>