загрузка и создание эскиза ошибки php

Я делаю свою первую cms для галереи, которая у меня есть. Я хочу иметь возможность загружать изображение в папку, но в то же время загружать миниатюру того же изображения в другую папку. Итак, я попытался использовать GD для миниатюр, но получаю следующую ошибку:

Warning: move_uploaded_file() expects parameter 1 to be string, resource given in C:\xampp\htdocs\liana\admin_panel\functions\gallery_upload.php on line 49

Но это строка, это путь к файлу.

галерея.php;

<form action="functions/gallery_upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="file" >
<button type="submit" name="submit"> UPLOAD </button>
</form>

функции/gallery_upload.php

<?php
//code for image upload, working normally
if (isset($_POST['submit'])){
    $file = $_FILES['file'];
    $fileName = $_FILES['file']['name'];
    $fileTmpName = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $fileError = $_FILES['file']['error'];
    $fileType = $_FILES['file']['type'];
    $fileExt = explode('.', $fileName);
    $fileActualExt = strtolower(end($fileExt));
    $allowed = array('jpg', 'jpeg', 'png');

    if (in_array($fileActualExt, $allowed)) {
        if ($fileError === 0) { //if there are no errors
            if ($fileSize < 500000) {
                $fileNameNew = uniqid('', true);    
                str_replace(".", "", $fileNameNew);
                $fileNameNew = $fileNameNew.".".$fileActualExt; //change img name based on time
                $fileDestination = '../../gallery/data1/images/'.$fileNameNew;
                move_uploaded_file($fileTmpName, $fileDestination);
        } else {echo 'too big';}} else {echo 'error';}} else {echo 'filetype not allowed';}}


// here I am trying to make the thumbnail

$thumb = resize_image($fileDestination, 200, 200); //I get said error in this line 
move_uploaded_file($thumb,'../../gallery/data1/tooltips/'.$fileNameNew);


// copy pasted function that resizes the image
function resize_image($file, $w, $h, $crop=FALSE) {
    list($width, $height) = getimagesize($file);
    $r = $width / $height;
    if ($crop) {
        if ($width > $height) {
            $width = ceil($width-($width*abs($r-$w/$h)));
        } else {
            $height = ceil($height-($height*abs($r-$w/$h)));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w/$h > $r) {
            $newwidth = $h*$r;
            $newheight = $h;
        } else {
            $newheight = $w/$r;
            $newwidth = $w;}}
    $src = imagecreatefromjpeg($file);
    $dst = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

вернуть $dst;}


person Sharo Kantir    schedule 12.08.2017    source источник
comment
Возможный дубликат предупреждения move_uploaded_file   -  person Mayank Vadiya    schedule 12.08.2017
comment
как такая же проблема? показывает другую ошибку   -  person Sharo Kantir    schedule 12.08.2017


Ответы (1)


Я только что использовал плагин под названием «wideimage». Я настоятельно рекомендую это, у вас будет тот же результат всего с 4 строками кода.

include "path/WideImage.php";
$thumb = WideImage::load($fileDestination);
$resized = $thumb->resize(100, 100);
$resized->saveToFile("path/". $fileNameNew .".jpg");
person Sharo Kantir    schedule 13.08.2017