使用php同时哈希并上传图像文件

时间:2017-10-13 17:59:18

标签: php hash

我正在尝试使用PHP将图像上传到服务器,并使用md5_file计算同一图像的哈希值。但不知何故,它既没有引用目录,也没有计算图像的哈希值。

代码: -

<html><body style="background-color:powderblue;">
<?php

session_start(); //declare you are starting a session





if(isset($_POST['submit'])){

    include'connect.php';

    $fname = $_POST['fi'];
    $filename = $_FILES['fileupload']['name'];
    $filetmp = $_FILES['fileupload']['tmp_name'];
    $filesize = $_FILES['fileupload']['size'];
    $file_basename = basename($_FILES['fileupload']['name']);
    $dir = "upload/";
    $final_dir = $dir.$file_basename;
    $hash = md5_file($final_dir);   
    $_SESSION['hash'] =$hash;


    $upload = move_uploaded_file($filetmp,$final_dir);
}




/* image_name= "$file_basename";
    image_path ="$final_dir";

*/

    /*Database Query*/**strong text**

        if($filesize > 1024000){
            echo("Greater then expected");
            }










if($selected){

    echo nl2br("Operation successful\n");
    echo nl2br("URL Record successfully\n");
    echo nl2br("$fname \n \n");

    }
else{
    echo("No No No ...");

}

?>

1 个答案:

答案 0 :(得分:0)

在将临时文件移动到最终目的地之前,只需对其进行哈希处理。

$hash = md5_file($filetmp);
...
$upload = move_uploaded_file($filetmp,$final_dir);