Code to get file size after upload and insert into table is not working

时光总嘲笑我的痴心妄想 提交于 2019-12-20 06:29:02

问题


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();

}

回答1:


You're using the wrong index:

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

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


来源:https://stackoverflow.com/questions/23958950/code-to-get-file-size-after-upload-and-insert-into-table-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!