Resim Yükleme - Latin sorunu chars

4 Cevap

Ben sunucu resim yüklemek için bu komut dosyasını kullanabilirsiniz:

 <?php

if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"  && ($_FILES["image_upload_box"]["size"] < 2000000))
    {

    	$max_upload_width = 450;
    	$max_upload_height = 450;
    	if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){
    		$max_upload_width = $_REQUEST['max_width_box'];
    	}    
    	if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){
    		$max_upload_height = $_REQUEST['max_height_box'];
    	}	
    	if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){	
    		$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
    	}		

    	$remote_file =$directory."/".$_FILES["image_upload_box"]["name"];
    	imagejpeg($image_source,$remote_file,100);
    	chmod($remote_file,0644);

    	list($image_width, $image_height) = getimagesize($remote_file);

    	if($image_width>$max_upload_width || $image_height >$max_upload_height){
    		$proportions = $image_width/$image_height;

    		if($image_width>$image_height){
    			$new_width = $max_upload_width;
    			$new_height = round($max_upload_width/$proportions);
    		}		
    		else{
    			$new_height = $max_upload_height;
    			$new_width = round($max_upload_height*$proportions);
    		}		


    		$new_image = imagecreatetruecolor($new_width , $new_height);
    		$image_source = imagecreatefromjpeg($remote_file);

    		imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
    		imagejpeg($new_image,$remote_file,100);

    		imagedestroy($new_image);
    	}

    	imagedestroy($image_source);



    }else{
       something....
    }

?>

This is works well, till i upload a photo with latin chars in filename. For example the filename: kék hegyek.jpg. After upload file name will be: KĂ©k hegyek.jpg

I bu nasıl çözebilir?

Teşekkür ederim

4 Cevap

Bu genellikle aşağı yatan dosya sistemi etmektir.

Ne dosya sistemi bu altında var mı?

Sayfanız Latin-1 UTF-8 ama sunucu olduğunu. Onlara aynı yapmak zorunda.

Bu bir sunucunun ne tür çalışıyor? Bu bir UTF-8 kodlanmış form var çok benziyor, ancak dosya adı bir yerde yol boyunca latin değiştirildi alır - muhtemelen dosya dosya sistemi yazılır zaman. Size bu çalıştırdığınız sunucu / işletim sisteminin ne tür bilmek önemlidir nedeni budur. Ben sonunda, kullanılan dosya sistemine aşağı bulunuyor.

Sunucunuzun dosya sistemi UTF-8 desteklemiyorsa, doğru bir karakter setine adı dönüştürmek için utf8_decode() veya iconv() kullanmayı deneyebilirsiniz.

Ayrıca non-latin karakterler sıyırma düşünebilirsiniz. İşte en sık en kolay yoludur, ben yapmak umlauts tüm zaman.

This is general good reading about encodings: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

I modify the code, as you suggested: This is just a snippet:

   $remote_file =$directory."/".$_FILES["image_upload_box"]["name"];
   $remote_file=utf8_decode($remote_file);
   imagejpeg($image_source,$remote_file,100);
   chmod($remote_file,0644);

Tamam, şimdi, görüntüyü yükledikten sonra, dosya adı doğrudur: Kék hegyek.jpg

Benim kod bu kısmı, ben dizin ve onları liste tüm görüntüleri okuyabilir:

  $images = glob("" . $directory . "*");
     $imgs = '';
     foreach($images as $image){ $imgs[] = "$image"; }
     $imgs = array_slice($imgs, 0, 20);
     foreach ($imgs as $img) {
  //  $img=utf8_decode($img); 
     echo  "<form action='datasheet_edit.php' id='$img' method='post'>";
     echo "<div class=\"photo\">"; 
     echo "<img  src='$img' width='100' height='50%' alt=\"\"><br>\n"; 
     echo "<a href=\"$img\">",basename($img),"</a><br>\n</div>"; 
     echo "<input type='hidden' id='fordelete' name='fordelete' value='$img' />";
     echo "</div>\n"; 
     echo "</form>";
     }

This is work well, but the mentioned file-name wrong: K�k hegyek.jpg I tried to use UTF8_DECODE here (the uncommented line), but so the output was: K?hegyek.jpg

Bundan sonra ben utf8_encode ve voila, çıkışını kullanmaya çalıştı: Kék hegyek.jpg

Ama maalesef, bağlantı coz kodu yanlış, 'bir bağlantı parçasıdır: http://localhost/page/K ÉK% 20hegyek.jpg.

Ve sorun i görüntüyü silebilirsiniz bir düğme var olmasıdır.

($ dosya) bağlantısını;

Dosya adı: Kék hegyek.jpg değil Kék% 20hegyek.jpg yüzden silemezsiniz.

Çıldırıyor im ...

Benim için nihai çözüm:

  1. Uzak dosya için "_", "alan" yerine
  2. Sonra $ uzak = utf8_decode ($ uzak);
  3. Ne zaman baskı filename $ img = utf8_encode ($ img);
  4. Ve ne zaman silmek için tıklayın: unlink (utf8_decode ($ _POST ['fordelete']));

Bu çözüm benim için çalışmak olduğunu. Whaah, ama benim için onun ok - Ben deşifre-encode-decode için en iyi yol değildir düşünüyorum.