This topic is locked

File Upload

4/11/2014 3:59:29 AM
PHPRunner General questions
B
bencroftweb author

I have a client that has to file upload areas - One private and one public.
They want to be able to make a selection of the private files public without having to download and then re-upload into public field.
We like/use the multi file option but I guess I could make multiple single fields with a publish to public tick box but then that would mess up the existing file structure.
Any thoughts?
Thanks
Ben

Sergey Kornilov admin 4/11/2014

It greatly depends on how you setup public and private areas in your project. Are they separate tables or just separate parts of the same table? Where public and private files are stored physically?

B
bencroftweb author 4/11/2014



It greatly depends on how you setup public and private areas in your project. Are they separate tables or just separate parts of the same table? Where public and private files are stored physically?


The fields are in the same table and all files (whether private or public) are kept in the same folder so all I would need to do the move the filename reference from one field to another. But we use multiple file upload and may only need to move 1 file link over out of 10.
Thanks
Ben

Sergey Kornilov admin 4/11/2014

I see what you saying. So there are two fields in the same table, one stores public files and another one stores private ones.
File info is stored in the database in JSON format (if you use multi-upload feature). What you need to do is to parse both public and private fields, converting them to PHP arrays. Remove the array record from the private field and add it to public one.
Here is the code sample that shows both JSON->PHP array conversion and also how to pack it back to JSON format:

http://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm
Something along the lines of the following:

$private = my_json_decode($values["private"]);

$public = my_json_decode($values["private"]);

$fileNameToMove="sample.pdf";
// scan files till we find one to be moved to public storage

for($i = 0; $i < count($private); $i++)

{

if ($private[$i]["usrName"]== $fileNameToMove)

{

$public[]= $private[$i];

unset($private[$i]);

break;

}
}



// update values of the field that stores files

$values["private"] = my_json_encode($private);

$values["public"] = my_json_encode($public);