
PHP - resize obrázku a $_FILES["image"]["name"]
Prosím o radu. Jsem už trochu zoufalý, protože tenhle problém převracím ze všech stran a nevím jak na něj.
Je možné, že jsem něco přehlédl, ale už opravdu asi nevidím co.
Skript kterým odesílám:
<?
echo '<form name="formular1" action="odkazy1.php" method="post">
Pořadí: <br>
<input type="text" name="poradi" size="2" maxlength="2"><br>
<br>
Alt: <br>
<input type="text" name="alternative" size="25" maxlength="35"><br> <br>
Adresa: <br>
<input type="text" name="adresa" size="25" maxlength="35"><br>
<br>
Ikona: <br>
<input type="file" name="image" size="40" alt="fotka"><br>
<br>
Text: <br>
<textarea name="text" cols="70" rows="5"></textarea><br>
<input type="hidden" name="akce" value="pridat">
<input type="submit" value="odeslat" class="tlacitko1">
</form>';
?>
Skript kterým zapisuju:
<?php
session_start();
session_register("ulozeno");
if (!$poradi || !$adresa || !$image || !$text)
{
$ulozeno = 1;
header ("Location: odkazy.php");
}
else
{
include("spojeni1.inc");
if ($image)
{
$soubor_name = ($_FILES["image"]["name"]);
$image = ($_FILES["image"]["name"]);
$size=GetImageSize($image);
$width=$size[0];
$height=$size[1];
}
if ($width)
$x_ratio=$max_width/$width;
if ($height)
$y_ratio=$max_height/$height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
switch ($size[2]) {
case 1: $src=imagecreatefromgif($image); break;
case 2: $src=imagecreatefromjpeg($image); break;
case 3: $src=imagecreatefrompng($image); break;
}
$dst=ImageCreateTrueColor($tn_width,$tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0,$tn_width,$tn_height,$width,$height);
switch ($size[2]) {
case 1: ImageGif($dst,$cil.'/'.$image_name,100); break;
case 2: ImageJpeg($dst,$cil.'/'.$image_name,100); break;
case 3: ImagePng($dst,$cil.'/'.$image_name); break;
}
@ImageDestroy($src);
@ImageDestroy($dst);
$update = mysql_query("INSERT INTO odkazy (poradi, alt, adresa, obrazek, text) VALUES ('$poradi', '$alternative', '$adresa', '$soubor_name', '$text') ");
mysql_close();
$ulozeno = 2;
header ("Location: odkazy.php");
}
?>
No a chybu kterou mi to hlásí:
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/www/mz-fans.cz/www/admin/odkazy1.php on line 50
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/www/mz-fans.cz/www/admin/odkazy1.php on line 51
Warning: Cannot modify header information - headers already sent by (output started at /home/www/mz-fans.cz/www/admin/odkazy1.php:50) in /home/www/mz-fans.cz/www/admin/odkazy1.php on line 65
Ještě jednou prosím o pomoc, a předem děkuju za postrčení správným směrem.