Autor Zpráva
surfer
Profil *
Vím, že to je hloupost, ale nechce mi vypisovat název souboru s typem. Ví někdo kde mám problém? Já nic nevidim :-(

<?
echo $_FILES["image"]["name"];
?>

<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" enctype="multipart/form-data" name="photo">
Foto: <input type="file" name="image" size="30"> <input type="submit" name="upload" value="Nahrát">
</form>
surfer
Profil *
Chyba je někde v proměných, pč obrázek nahraje, ale na další funkce už kašle.

<?php
$upload_dir  = "upload_pic";           // Adresář pro obrázky, které mají být ukládány do
$upload_path = $upload_dir."/";				// Cesta k místu, kde bude obraz uložen
$large_image_name = "standart".$_FILES["image"]["name"].".jpg";           // Nový název pro velký obrázek
$thumb_image_name = "mini_".$_FILES["image"]["name"].".jpg";   // Nové jméno na miniaturu
$max_file     = "548576";             // Cca 1 MB.
$max_width    = "550";                // Maximální šířka povolena pro velký obrázek
$thumb_width  = "178";                // Šířka miniatury
$thumb_height = "178";                // Výška miniatury

// Image funkce
// Nemusíte měnit tyto funkce
function resizeImage($image,$width,$height,$scale) {
	$newImageWidth  = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	$source   = imagecreatefromjpeg($image);
	imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
	imagejpeg($newImage,$image,90);
	chmod($image, 0777);
	return $image;
}
// Nemusíte měnit tyto funkce
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
	$newImageWidth  = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	$source = imagecreatefromjpeg($image);
	imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
	imagejpeg($newImage,$thumb_image_name,90);
	chmod($thumb_image_name, 0777);
	return $thumb_image_name;
}
// Nemusíte měnit tyto funkce
function getHeight($image) {
	$sizes  = getimagesize($image);
	$height = $sizes[1];
	return $height;
}
// Nemusíte měnit tyto funkce
function getWidth($image) {
	$sizes = getimagesize($image);
	$width = $sizes[0];
	return $width;
}

// Image Pobočky
$large_image_location = $upload_path.$large_image_name;
$thumb_image_location = $upload_path.$thumb_image_name;

//Create the upload directory with the right permissions if it doesn't exist
if(!is_dir($upload_dir)){
	mkdir($upload_dir, 0777);
	chmod($upload_dir, 0777);
}

// Zjistit, zda některé obrazy se stejnými názvy již existují
if (file_exists($large_image_location)){
	if(file_exists($thumb_image_location)){
		$thumb_photo_exists = "<img src=\"".$upload_path.$thumb_image_name."\" alt=\"Thumbnail Image\"/>";
	} else {
		$thumb_photo_exists = "";
	}
   	$large_photo_exists = "<img src=\"".$upload_path.$large_image_name."\" alt=\"Large Image\"/>";
} else {
   	$large_photo_exists = "";
	$thumb_photo_exists = "";
}

if (isset($_POST["upload"])) { 
	// Get informací o souboru
	$userfile_name = $_FILES['image']['name'];
	$userfile_tmp = $_FILES['image']['tmp_name'];
	$userfile_size = $_FILES['image']['size'];
	$filename = basename($_FILES['image']['name']);
	$file_ext = substr($filename, strrpos($filename, '.') + 1);
	
	//Zpracovat pouze v případě, že soubor je ve formátu JPG, a pod povolený limit
	if((!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0)) {
		if (($file_ext!="JPG" || $file_ext!="jpg"  || $file_ext!="Jpg" ) && ($userfile_size > $max_file)) {
			$error= "Pouze formát jpg do 500Kb je akceptován pro upload.";
		}
	} else {
		$error= "Zvolte obrázek JPEG pro upload";
	}
	//Everything is ok, so we can upload the image.
	if (strlen($error)==0){
		
		if (isset($_FILES['image']['name'])){
			
			move_uploaded_file($userfile_tmp, $large_image_location);
			chmod($large_image_location, 0777);
			
			$width = getWidth($large_image_location);
			$height = getHeight($large_image_location);
			//Měřítko obrázku, pokud je větší než šířka, že výše uvedená
			if ($width > $max_width){
				$scale = $max_width/$width;
				$uploaded = resizeImage($large_image_location,$width,$height,$scale);
			}else{
				$scale = 1;
				$uploaded = resizeImage($large_image_location,$width,$height,$scale);
			}
			//Odstranit náhled souboru, takže uživatel může vytvořit nový
			if (file_exists($thumb_image_location)) {
				unlink($thumb_image_location);
			}
		}
		//Obnovit stránku ukázat nový obrázek
		header("location:".$_SERVER["PHP_SELF"]);
		exit();
	}
}

if (isset($_POST["upload_thumbnail"]) && strlen($large_photo_exists)>0) {
	//Získejte nové souřadnice pro oříznutí obrázku.
	$x1 = $_POST["x1"];
	$y1 = $_POST["y1"];
	$x2 = $_POST["x2"];
	$y2 = $_POST["y2"];
	$w  = $_POST["w"];
	$h  = $_POST["h"];
	//Měřítko obrázku thumb_width že výše uvedená
	$scale = $thumb_width/$w;
	$cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale);
	//Znovu načíst stránku znovu zobrazit náhled
	header("location:".$_SERVER["PHP_SELF"]);
	exit();
}

if ($_GET['a']=="delete"){
	if (file_exists($large_image_location)) {
		unlink($large_image_location);
	}
	if (file_exists($thumb_image_location)) {
		unlink($thumb_image_location);
	}
	header("location:".$_SERVER["PHP_SELF"]);
	exit(); 
}
?>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=windows-1250">
	<title>image upload &amp; crop</title>
	<script type="text/javascript" src="jquery.js"></script>
</head>
<body>

<?php
//Zobrazit pouze javacript když obraz byl nahrán
if(strlen($large_photo_exists)>0){
	$current_large_image_width = getWidth($large_image_location);
	$current_large_image_height = getHeight($large_image_location);?>
<script type="text/javascript">
function preview(img, selection) {
	var scaleX = <?php echo $thumb_width;?> / selection.width;
	var scaleY = <?php echo $thumb_height;?> / selection.height;

	$('#thumbnail + div > img').css({
		width: Math.round(scaleX * <?php echo $current_large_image_width;?>) + 'px',
		height: Math.round(scaleY * <?php echo $current_large_image_height;?>) + 'px',
		marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
		marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
	});
	$('#x1').val(selection.x1);
	$('#y1').val(selection.y1);
	$('#x2').val(selection.x2);
	$('#y2').val(selection.y2);
	$('#w').val(selection.width);
	$('#h').val(selection.height);}
</script>
<?php 
}
// Zobrazení chybové zprávy, pokud existují
if(strlen($error)>0){
	echo "<p><strong>Error!</strong> ".$error."</p>";
}
if(strlen($large_photo_exists)>0 && strlen($thumb_photo_exists)>0){
	echo $large_photo_exists."&nbsp;".$thumb_photo_exists;
	echo "<p><a href=\"".$_SERVER["PHP_SELF"]."?a=delete\">Vymazat obrázek</a></p>";
}
?>
surfer
Profil *
Pokud tyhle položky změním na neco.jpg, tak všechno maká.
$large_image_name = "neco.jpg";           // Nový název pro velký obrázek
$thumb_image_name = "mini_neco.jpg"; 
AM_
Profil
surfer:
Chyba je někde v proměných
Takovou chybu obvykle nejlépe odhalí programátor sám, vloží do kódu pár "echo" klíčových proměnných, aby zjistil, kde přesně je chyba. Zírat na dvěstěřádkový kód a divit se, proč to nejde, můžeme stejně dobře, jako ty, a vzhledem k tomu, že ty jsi autorem kódu, máš i v tomto jistý náskok.
Toto fórum slouží k dávání rad lidem, kteří vědí přesně, v čem je jejich problém, nikoli ladění kódů a hledání chyb zdarma.
surfer
Profil *
Máte pravdu :-) Omlouvám se, že jsem optěžoval.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0