问题
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