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

时间:2018-02-28 12:16:23

标签: php image-uploading

在我的代码中,当用户上传一张照片时,在我的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; 
     }
?>

文件正在上传,但是宽度变量中没有值,有什么不对,或者我的方法是错误的。

2 个答案:

答案 0 :(得分:0)

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

  

如果文件有效,它将被移动到目的地给出的文件名。

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

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

答案 1 :(得分:0)

试试这段代码它运行正常 检查一下,让我

#ifndef cplusplus