上传并插入表后获取文件大小的代码不起作用 [英] Code to get file size after upload and insert into table is not working

查看:58
本文介绍了上传并插入表后获取文件大小的代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL/PHP项目,当前有一个文件表,该表创建虚拟文件夹并链接到上载的文件,上载和访问工作正常,但是我刚刚添加了大小"字段并修改了我的代码以进行更新上传到表格后的文件大小,但是代码不起作用.我没有收到任何错误,文件仍然上传,但是代码在相关字段中插入了空值.代码如下:

I have a MySQL/PHP project that currently has a files table that creates virtual folders and links to uploaded files, the upload and accessing works fine, however i have just added the field 'size' and have amended my code to update the file size after upload into the table, however the code is not working. I get no errors and the file still gets uploaded but the code is inserting a null value into the relevant field. Code is below:

global $dal;
$tblDocs = $dal->Table("doc_files");
$fileArray = my_json_decode($values["file"]);

for($i = 0; $i < count($fileArray); $i++)
{
$tblDocs->Value["parent_folder_id"]=$_SESSION["current_folder"];
$tblDocs->Value["file_type"]="file";
$tblDocs->Value["file"]=my_json_encode(array($fileArray[$i]));
$tblDocs->Value["hash"]=generatePassword(HASH_LENGTH);
$tblDocs->Value["name"]=$fileArray[$i]["usrName"];
$tblDocs->Value["ownerid"]=$_SESSION["user_id"];
$tblDocs->Value["created"]=now();
$tblDocs->Value["filesize"]=formatBytes($fileArray[0]["size"],2);

$tblDocs->Add();

}

推荐答案

您使用了错误的索引:

$tblDocs->Value["name"]=$fileArray[$i]["usrName"];
                                   ^^--here you use the loop index

$tblDocs->Value["filesize"]=formatBytes($fileArray[0]["size"],2);
                                                   ^---hard-coded index

这篇关于上传并插入表后获取文件大小的代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆