Hi, I build a little Website fully in flash, which as one of many things enables the user to upload photos to the server to a specific direction, they get resized and their names are then changed to a number (thats why I connect to database, the table is chosen by flash, it tells me the number of the next picture) . This works great when I tried it out at my local server, as long as the pictures are not to big in size, or I think if they don’t have to many pixels. As soon as they get bigger, it either takes forever or just doesn’t work (I haven’t waited for more than an hour yet).
I don’t really want people to have a limit on file size though. Any idea where the problem in my code is?
I know its not well written and all, but its my first php script, I usually only do action script.
PHP:
[php]
<?php
//connect to db
$link = mysql_connect("somehost","user","pw");
mysql_select_db("somedb");
//define variables from POST and db
$schirm = $_POST['schirm'];
$table = strtolower($schirm)."img";
$query = 'SELECT * FROM '.$table.' ORDER BY id DESC LIMIT 1';
$results = mysql_query($query);
while ($line = mysql_fetch_assoc($results)){
$id = $line["id"]+1;
};
//get extension and file size as well as name etc.
$filenameg = $_FILES['Filedata']['name'];
$filename = substr_replace($filenameg,"IMG_".$id,0,strrpos($filenameg,"."));
$filetmpname = $_FILES['Filedata']['tmp_name'];
$fileType = $_FILES["Filedata"]["type"];
$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
$imagesize = getimagesize($filetmpname);
$str = $filenameg;
$i = strrpos($str,".");
$l = strlen($str) - $i;
$extension = strtolower(substr($str,$i+1,$l));
//change image size if its bigger than 800x600
if($imagesize[0]>800){
if($extension=="jpg" || $extension=="jpeg" )
{
$src = imagecreatefromjpeg($filetmpname);
}
else if($extension=="png")
{
$src = imagecreatefrompng($filetmpname);
}
else
{
$src = imagecreatefromgif($filetmpname);
}
if($imagesize[0]>($imagesize[1]*4/3))
{
$newwidth=800;
$newheight=($imagesize[1]/$imagesize[0])*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$imagesize[0],$imagesize[1]);
imagejpeg($tmp,"images/".$table."/".$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
else{$newheight=600;
$newwidth=($imagesize[0]/$imagesize[1])*$newheight;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$imagesize[0],$imagesize[1]);
imagejpeg($tmp,"images/".$table."/".$filename,100);
imagedestroy($src);
imagedestroy($tmp);};
}
else if($imagesize[1]>600){
if($extension=="jpg" || $extension=="jpeg" )
{
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
$newheight=600;
$newwidth=($imagesize[0]/$imagesize[1])*$newheight;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$imagesize[0],$imagesize[1]);
imagejpeg($tmp,"images/".$table."/".$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
else{$move = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$table."/".$filename);};
//enter data into db and close connection
$entry = mysql_query("INSERT INTO
$table(name,width,height)VALUES('$filename','$newwidth','$newheight')");
mysql_close($link);
?>
[/php]
Thank you already for taking a look at it.