PHP 图片文件上传停止工作

PHP Image file uploads stopped working

我一直在使用我构建的这个 PHP 脚本很长时间了,直到最近才停止上传文件。我不知道出了什么问题,PHP FPM 文件上传设置为 1000m,我在 Nginx 上 运行。文件权限设置正确并使用 777 权限测试。

这是我的脚本:

 

<?php

    session_start();
    
if(!isset($_SESSION["user"]) or !is_array($_SESSION["user"]) or empty($_SESSION["user"])) {
      // redirect to login page
}
$dbhost   = "*.com";
$dbname   = "*";
$dbuser   = "*";
$dbpass   = "*";
 
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data


$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

/*
echo $target_file;

echo $imageFileType;
*/
     $date = date('Y-m-d') ."\n";
     $now = time(); $utc_time = $now - intval(date('Z', $now));
     $time = date('H:i:s', $now);
     $post_id=(uniqid());
     $MediaTxt = $_POST['MediaTxt'];

  if ($imageFileType == "jpg" || $imageFileType == "JPG")
   { 
   $imageFileType = strtolower($imageFileType);
     $ip = $_POST['ip'];
     $UsrFName = $_POST['UsrFName'];
     $UsrLName = $_POST['UsrLName'];
     $UsrID = $_POST['UsrID'];
     $format = 'img';
     $file_format = 'jpg';
     $MediaTxt = $_POST['MediaTxt'];
     $author_id = $_POST['author_id'];
     $relation = $_POST['relation'];
     $MediaTxtNw = strip_tags($MediaTxt, '<h1><h2><h3><h4><h5><h6><img><video><audio><iframe><a>');
     
     $tag = $MediaTxtNw;
     
     preg_match_all("/(#\w+)/", $tweet, $tags);
     
     $tweet = $MediaTxtNw;
     
     preg_match_all("/(#\w+)/", $tweet, $matches);
     
     foreach($matches[0] as $child) {
       $tags = $child . "\n" ;
       $tagsnew = preg_replace('/#([\w-]+)/i', '', $tags);

     $sql = "INSERT INTO hashtags (tag,post_id,uid,time,date) VALUES ('$tagsnew','$post_id','$UsrID','$time','$date');";
     
      if ($conn->query($sql) === TRUE) {
      } else {
      }
     }
     

     
     $target_dir = ('../media/jpg/');
     $target_file = $target_dir . $post_id . $author_id .'.'.pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_EXTENSION);
     $uploadOk = 1;
     $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
     (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file));

     
     $sql = "INSERT INTO media (ip,date,time,firstname,lastname,userID,post_id,format,file_format,MediaTxt,author_id,relation) VALUES
      (:sasa,:sasad,:sasadf,:sasafds,:sasafda,:sasdfhj,:sasdhadka,:sasdhadkas,:sasdhadkasdas,:sashasdas,:aauutthorrid,:rrhjkjahtn)";
     $q = $conn->prepare($sql);
     $q->execute(array(':sasa'=>$ip,':sasad'=>$date,':sasadf'=>$time,':sasafds'=>$UsrFName,':sasafda'=>$UsrLName,':sasdfhj'=>$UsrID,
     ':sasdhadka'=>$post_id,':sasdhadkas'=>$format,':sasdhadkasdas'=>$file_format,':sashasdas'=>$MediaTxtNw,
     ':aauutthorrid'=>$author_id,':rrhjkjahtn'=>$relation));
     
   }

尝试通过在某些地方放置一些 die('test'); 代码来调试您的代码...然后您可以查看您的死代码所在的位置并对其进行调试。并将其放在您的代码之上:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

error_reporting(E_ALL);