Tack för det snabba svaret, och välkomnandet till wF. Fick tipset av en trevlig prick vid namn Jesper att detta skulle vara det bästa stället.
Eftersom jag bara är nybörjare, och kan för lite så undrar jag hur man mer precis kopplar ihop det du skrev och den befintliga funktionen.
Den befintliga koden kollar även om det filnamnet redan finns etc, och för in viss data i en mysqldatabas.
Här kommer koden:
<?
if(isset($uploadbutton))
{
for($counter=1;$counter<=$numphotos;$counter++)
{
$query = mysql_query("SELECT * FROM gallery_photos WHERE photoUser=$loggedUserID AND photoFile='".$_FILES['photofile'.$counter]['name']."' ") or die ("Error: ".mysql_error());
$numRows = mysql_num_rows($query);
if($numRows>0)
{$exists=true;}
else
{$exists=false;}
if($exists==false)
{
$image_info = getimagesize($_FILES['photofile'.$counter.'']['tmp_name']);
$photowidth = $image_info[0];
$photoheight = $image_info[1];
$photopixelsize = $photowidth."x".$photoheight;
$filename = $_FILES['photofile'.$counter.'']['name'];
$photodate = date("Y-m-d");
$filesizekb = $_FILES['photofile'.$counter.'']['size']/1024;
settype($filesizekb,'integer');
if($_FILES['photofile'.$counter.'']['type'] == 'image/jpg' || $_FILES['photofile'.$counter.'']['type'] == 'image/jpeg' || $_FILES['photofile'.$counter.'']['type'] == 'image/pjpeg')
{
echo "Type: ".$_FILES['photofile'.$counter.'']['type']."<br>";
move_uploaded_file($_FILES['photofile'.$counter.'']['tmp_name'], "gallery/original/".$loggedUser."/".$filename)
or die ("Could not copy");
/* Resize and create a thumb */
$image_path = "gallery/original/".$loggedUser."/".$filename;
$imgsource = imagecreatefromjpeg($image_path);
if($photowidth>$photoheight)
{
$imgdest = imagecreatetruecolor(90, 60);
imagecopyresized($imgdest, $imgsource, 0, 0, 0, 0,
90, 60, $photowidth, $photoheight);
}
else if($photowidth == $photoheight)
{
$imgdest = imagecreatetruecolor(90, 90);
imagecopyresized($imgdest, $imgsource, 0, 0, 0, 0,
90, 90, $photowidth, $photoheight);
}
else
{
$imgdest = imagecreatetruecolor(60, 90);
imagecopyresized($imgdest, $imgsource, 0, 0, 0, 0,
60, 90, $photowidth, $photoheight);
}
imagejpeg($imgdest,"gallery/thumbs/".$loggedUser."/".$filename,100);
/* Resize and create a full */
$max_width = 500;
$max_height = 500;
$x_ratio = $max_width / $photowidth;
$y_ratio = $max_height / $photoheight;
if (($photowidth <= $max_width) && ($photoheight <= $max_height))
{
$new_width = $photowidth;
$new_height = $photoheight;
}
else if (($x_ratio * $photoheight) < $max_height)
{
$new_height = ceil($x_ratio * $photoheight);
$new_width = $max_width;
}
else
{
$new_width = ceil($y_ratio * $photowidth);
$new_height = $max_height;
}
$text = "©";
$font = 'gallery/impact.ttf';
$imgsource2 = @imagecreatefromjpeg($image_path);
$color = imagecolorallocatealpha($imgsource2, 255, 255, 255, 70);
$imgdest2 = imagecreatetruecolor($new_width, $new_height);
imagettftext($imgsource2, 200, 0, 80, 260, $color, $font, $text);
imagecopyresized($imgdest2, $imgsource2, 0, 0, 0, 0, $new_width, $new_height, $photowidth, $photoheight);
imagejpeg($imgdest2,"gallery/full/".$loggedUser."/".$filename,90);
mysql_query("INSERT INTO gallery_photos (photoUser,photoThumb,photoFull,photoFile,photoDate,photoPixelSize,photoFileSize,photoComplete) VALUES
('$loggedUserID','$filename','$filename','$filename','$photodate','$photopixelsize','$filesizekb','no')")
or die ("Error: ".mysql_error());
}
else
{
echo "Error: File type<br>";
}
echo "Temp Name: ".$_FILES['photofile'.$counter.'']['tmp_name']."<br>";
echo "Name: ".$_FILES['photofile'.$counter.'']['name']."<br>";
echo "Size: ".$_FILES['photofile'.$counter.'']['size']."<br>";
echo "Error: ".$_FILES['photofile'.$counter.'']['error']."<br><br>";
}
else
{
echo $_FILES['photofile'.$counter.'']['name']." finns redan, byt namn på filen.<br><br>";
}
}
}
?>
Sedan eftersom det är fler än jag som laddar upp så kanske jag kan ha sökvägen så här:
$dir = "tmp/".$loggedUser."/";
Kommer det även funka med att han skriver ut filestorlek m.m. som den gör nu?
Sedan undrar jag hur själva knappen bör vara utformad?
Så här?:
<input name="uploadbutton" type="submit" id="uploadbutton" value="Ladda in dina bilder">
Åh så bra om jag kunde få detta att funka! =)