上传图片时获取图片宽度 PHP

Get image width while uploading image PHP

在我的代码中,当用户上传图片时,在我的 php 代码中,我想在上传图片时读取图片的宽度,下面是我的代码 --

<?php
    require_once('config.php');

    $file_path = $_SERVER['DOCUMENT_ROOT']."AndroidApp/VideoUploads/Thumbnails/";

    $emailid=$_GET['emailid'];
    $randNum=$_GET['randNum'];
    $ext = findexts ($_FILES['uploaded_file']['name']) ;
    $thumb_url="DoUpNow_Funny_Video_Thumb"."_".$randNum.".".$ext;

    $file_path = $file_path.$thumb_url;

    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path) ){

        list($width) = getimagesize($_FILES['uploaded_file']['tmp_name']);

        $stmt2 = $linkID1->prepare("update VideoUploads set video_thumb=?, width=? where emailid=? and randNum=?");
        $stmt2->bind_param("ssss", $thumb_url,$width,$emailid,$randNum);
        $stmt2->execute();
        $stmt2->close();
        echo "success";
    } else{
        echo "fail";
    }

    function findexts ($filename) 
     { 
     $filename = strtolower($filename) ; 
     $exts = split("[/\.]", $filename) ; 
     $n = count($exts)-1; 
     $exts = $exts[$n]; 
     return $exts; 
     }
?>

正在上传文件,但是width变量没有值,是有什么问题,还是我的方法不对。

move_uploaded_file()之后,tmp_name变量引用了一个不再存在的文件,它被移动了。

If the file is valid, it will be moved to the filename given by destination.

因此,使用 $file_path 获取您的文件信息:

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path) ){
    list($width) = getimagesize($file_path);

试试这个代码,它工作正常 检查这个,让我

 <?php
 $image_info = getimagesize($_FILES["uploaded_file"]["tmp_name"]);
 $image_width = $image_info[0];
 $image_height = $image_info[1];
 ?>