MySQL 值不显示在图片名称中

MySQL value don't show in picture name

本文关键字:显示 MySQL      更新时间:2023-09-26

我有一个上传图片的代码。上传图片后,用户可以对其进行裁剪。然后,图片与$new_name一起调用。我唯一的问题是,在$new_name中,$_GET['MomentEvent']永远不会出现在图片名称中。但是当我回应它时,它看起来很正常。那么,我怎样才能让它也出现在$new_name中呢?

有关信息,MomentEvent请参阅创建的每个新页面的唯一键。因此,当用户上传图片时,它只会在页面上显示具有良好MomentEvent的图片。

编辑:看起来问题来自这一行:echo $new_name."?".time();,因为当我尝试只回声$_GET['MomentEvent']时,什么也没发生。

编辑2:看起来问题来自if(isset($_GET['t']) and $_GET['t'] == "ajax"),因为最后一个回声,它在外面,所有工作,但回声在里面,没有任何工作。但我仍然不知道出了什么问题...

<?php
include('db.php');
session_start();
     $session_id=$_SESSION['id']; // Or Session ID
         $actual_image_name = time().substr($txt, 5).".".$ext;
         $t_width = 450; // Maximum thumbnail width
         $t_height = 150; // Maximum thumbnail height
              $new_name = "$actual_image_name".$_GET['MomentEvent'].".jpg"; // Thumbnail image name
              $path = "images/";
         if(isset($_GET['t']) and $_GET['t'] == "ajax")
         {
         extract($_GET);
             $ratio = ($t_width/$w); 
             $nw = ceil($w * $ratio);
             $nh = ceil($h * $ratio);
             $nimg = imagecreatetruecolor($nw,$nh);
             $im_src = imagecreatefromjpeg($path.$img);
             imagecopyresampled($nimg,$im_src,0,0,$x1,$y1,$nw,$nh,$w,$h);
             imagejpeg($nimg,$path.$new_name,90);
         mysql_query("UPDATE users_event SET image_small='$new_name' WHERE MomentEvent='".$_GET['MomentEvent']."'");
         echo $new_name."?".time();
         exit;
         }
     echo $new_name;
 ?>

不要使用提取。 通常使用它是一种不好的做法,尤其是在_get变量上......它使您面临DOS攻击,有人可以用数百个不需要的变量淹没您的查询字符串。

http://php.net/manual/en/function.extract.php

只需单独引用关联数组项即可。