图像上载到目录并进行裁剪 session_start(); 需要“../vendor/autoload.php”; 使用App\用户; $user=新用户(); ?>

图像上载到目录并进行裁剪 session_start(); 需要“../vendor/autoload.php”; 使用App\用户; $user=新用户(); ?>,php,html,Php,Html,因为您正在调用不存在的文件 session_start(); require '../vendor/autoload.php'; use App\Users; $user = new Users(); ?> <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.m

因为您正在调用不存在的文件

session_start();

require '../vendor/autoload.php';

use App\Users;

$user = new Users();


?>

   <html>
   <head>
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
             integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
             crossorigin="anonymous">
   </head>
   <form method="post" enctype="multipart/form-data">
       <br>
       <input type="file" name="userimage" class="btn btn-outline-secondary"><br><br>
       <input type="submit" name="verzendphoto" value="Verzend" class="btn btn-primary">
   </form>
   </html>


<?php

if (isset($_POST['verzendphoto'])) {
   $target_dir = "C:/xampp/htdocs/eduflow/code/uploads/";
   $target_file = $target_dir . basename($_FILES["userimage"]["name"]);
   $uploadOk = 1;
   $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));

   if ($imageFileType != "png") {
       echo "Sorry, alleen PNG bestanden.";
       $uploadOk = 0;
   }
   if (file_exists($target_file)) {
       echo "Sorry, bestand bestaat al.";
       $uploadOk = 0;
   }
   if ($uploadOk == 0) {
       echo "Sorry, je bestand is niet geupload.";
// if everything is ok, try to upload file.
   } else {
       // Moves the file to the directory.

       if (move_uploaded_file($_FILES["userimage"]["tmp_name"], $target_file)) {
           echo "The file " . basename($_FILES["userimage"]["tmp_name"]) . " has been uploaded.";
           $image = imagecreatefrompng($_FILES['userimage']['tmp_name']);
           $values = [
             'user_image' => '/eduflow/code/uploads/' . imagecrop($image, ['x' => 0, 'y' => 0, 'width' => 54, 'height' => 54]  ),
           ];
           $user->updateUserPhoto($_SESSION['user_id'], $values);
       } else {
           echo "Sorry, er was een fout bij het uploaden van uw foto.";
       }
   }
}
改为

$image = imagecreatefrompng($_FILES['userimage']['tmp_name']);

而且,
$\u文件['userimage']['tmp\u name']
不再存在,因为当我将代码更改为您建议的输出时,您已将其移动到这里。警告:imagecreatefrompng():'C:/xampp/htdocs/eduflow/code/uploads/social-media-button-menu-gradient-png_121951.png'在第51行的C:\xampp\htdocs\eduflow\code\admin\photo\u import.php中不是有效的png文件。警告:imagecrop()希望参数1是资源,bool在第53行的C:\xampp\htdocs\eduflow\code\admin\photo\u import.php中给出
$image = imagecreatefrompng($target_file);