function upload_image()
{
if(isset($_FILES['user_image']))
{
// Count total files
$countfiles = count($_FILES['user_image']['name']);
for($i=0;$i<$countfiles;$i++){
$extension = explode('.', $_FILES['user_image']['name'][$i]);
$new_name = rand() . '.' . $extension[1];
$destination = '../portfolio/upload/' . $new_name;
$thumbDestination = '../portfolio/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $destination);
resize($destination, $thumbDestination, 300);
}
return $new_name;
}
}
if($_POST["operation"] == "Add")
{
$image = '';
if($_FILES["user_image"]["name"] != '')
{
$image = upload_image();
}
$statement = $connection->prepare("
INSERT INTO portfolio (image, image_mini)
VALUES (:image, :image_mini)
");
$result = $statement->execute(
array(
':image' => $image,
':image_mini' => $image
)
);
if(!empty($result))
{
echo 'Фото Добавлено';
}
}
function upload_image_array()
{
$res = array();
if(isset($_FILES['user_image']))
{
// Count total files
$countfiles = count($_FILES['user_image']['name']);
for($i=0;$i<$countfiles;$i++){
$extension = explode('.', $_FILES['user_image']['name'][$i]);
$new_name = rand() . '.' . $extension[1];
$destination = '../portfolio/upload/' . $new_name;
$thumbDestination = '../portfolio/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $destination);
resize($destination, $thumbDestination, 300);
$res[] = $new_name;
}
return $res;
}
}
if($_POST["operation"] == "Add")
{
$images = array();
if($_FILES["user_image"]["name"] != '')
{
$images = upload_image_array();
}
foreach ($images as $image){
$statement = $connection->prepare("
INSERT INTO portfolio (image, image_mini)
VALUES (:image, :image_mini)
");
$result = $statement->execute(
array(
':image' => $image,
':image_mini' => $image
)
);
}
if(!empty($result))
{
echo 'Фото Добавлено';
}
}