Zrobiłem coś takiego. Dlaczego nie działa?
if(count($_FILES["file"]["name"]) > 0)
{
for($count=0; $count<count($_FILES["file"]["name"]); $count++)
{
$file_name = $_FILES["file"]["name"][$count];
$tmp_name = $_FILES["file"]['tmp_name'][$count];
$file_array = explode(".", $file_name);
$file_extension = end($file_array);
$source_properties = getimagesize($file_name);
//$image_type = $source_properties[2];
$image_resource_id = imagecreatefromjpeg($file_name);
$target_layer = fn_resize($image_resource_id,$source_properties[0],$source_properties[1]);
imagejpeg($target_layer,$_FILES["file"]["name"] . "_thump.jpg");
if(file_already_uploaded($file_name, $db2))
{
$file_name = $file_array[0] . '-'. rand() . '.' . $file_extension;
}
$location = 'C:\xampp1\htdocs\stepbystep2\img\img' . $count.'.' .$file_extension;
if(move_uploaded_file($tmp_name, $location))
{
$query = "INSERT INTO rotator (zdjecie, tekst, active) VALUES ('img".$count.'.' .$file_extension ."', '', 'TAK') ";
$statement = $db2->prepare($query);
$statement->execute();
}
}
}
function file_already_uploaded($file_name, $db2)
{
$query = "SELECT * FROM rotator WHERE zdjecie = '".$file_name."'";
$statement = $db2->prepare($query);
$statement->execute();
$number_of_rows = $statement->rowCount();
if($number_of_rows > 0)
{
return true;
}
else
{
return false;
}
function fn_resize($image_resource_id,$width,$height) {
$target_width =200;
$target_height =200;
$target_layer=imagecreatetruecolor($target_width,$target_height);
imagecopyresampled($target_layer,$image_resource_id,0,0,0,0,$target_width,$target_height, $width,$height);
return $target_layer;
}
}