tags:

views:

32

answers:

3

i need to mimic how an upload form work. i need to store a file into database and uploads the $_FILES into our folders. The problem every bit of code of the models and the form itself is based on legacy code. I don't have the the gut to strip all code and start over. I prefer to let it be

So, my goal is how to uplaod file without use the previous form and then only serialize/unserialize an object consist of filename and url. while the file itself have been story via copy function and not uploads form.

+1  A: 

Yes, it is possible to serialize $_FILES array;

$upload = serialize($_FILES["file"]);
Alexander.Plutov
+1  A: 

If your code is dependent on the contents of the $_FILES variable then yes, assigning to it (whether the contents are from a serialised version in a database or wherever) should have the expected behaviour.

Generally speaking, contriving a small test is a much better way of finding out if something will work for your particular situation than asking people on the internet to speculate.

Gian
+1  A: 

The only critical part of the $_FILES array for any particular request is the ...['tmp_name'] portion, since that points to where PHP saved the uploaded file. Save a copy of a $_FILES that's set up the way you want to test (with however many files you want), then manually change the tmp_name to point to actual files on your server, rather than the random garbage names that PHP autoassigns to uploads, and you could be able to reuse a copy of the data as many times as you want, as long as your scripts don't move/delete/munge the files you're pointing at.

So, something like:

$_FILES['file1']['tmp_name'] = '/path/to/file/to/test/with';
$_FILES['file2']['tmp_name'] = '/some/other/path/or/file/for/testing';

$savedfiles = serialize($_FILES);

and then you can stick a

$_FILES = unserialize($savedfiles);

wherever it's appropriate for testing your app.

Marc B