记录在数据库中的值与变量

时间:2015-10-29 14:26:00

标签: php mysql

我正在尝试在php中保存文件,并且使用日期,时间和随机数更改文件的名称。该文件的相同名称正在数据库中记录,但数据库中记录的名称总是与生成并用于文件上载的数字相差几位。看起来当上传文件的操作发生时,随机数正在重新生成... :(但应该发生这种情况。

<?php
$id = intval($_REQUEST['id']);

include 'conn.php';

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

$today = date('y-m-j');
$time1 = date('H-i', time()); // 12:50:29

$temp = mt_rand ( 0 , 200 );

$newfilename = $today.'_'.$temp.'_'.$time1.'.zip'; //generates a random name based on time for the 

$DBnewfilename="http://localhost/purchasesystem/uploads/".$newfilename;


$sql = "update PURCHASE_REQUESTS set URL='$DBnewfilename' where id=$id";         

$result = @mysql_query($sql);



    if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "uploads/".$newfilename)){

            echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";

    } else {
            echo "Sorry, there was an error uploading your file.";
        }

数据库记录URL设置为TEXT(但我也尝试过varchar而没有结果):(

非常感谢你能给我的任何建议。 可乐

0 个答案:

没有答案