Hey,
I am using the PclZip class. It works great, but the feature I REALLY want only works if you HARD code it.
Basically, I want to be able to dynamically, at any point, create 5 or 10 or 44 instances of the bolded code. It’s THIS one in particular I wish I could dynamically spit out 20 times if need be:
[B]array( PCLZIP_ATT_FILE_NAME => ‘data/file1.txt’,
PCLZIP_ATT_FILE_NEW_FULL_NAME => ‘newdir/newname.txt’
)
For instance, if I have 20 files, twenty of the above arrays
are created.
I know how to build the STRING to store 20 of them, but when I replace the bolded code below with the STRING that holds the text you see in bold, it doesn’t treat it literally.
[/B]
Below is the full example their site gives:
$list = $archive->create([B]array(
array( PCLZIP_ATT_FILE_NAME => 'data/file1.txt',
PCLZIP_ATT_FILE_NEW_FULL_NAME => 'newdir/newname.txt'
),
array( PCLZIP_ATT_FILE_NAME => 'data/file2.txt',
PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'newfilename.txt'
),
)[/B],
PCLZIP_OPT_ADD_PATH, 'newpath',
PCLZIP_OPT_REMOVE_PATH, 'data');
The Error I Receive if I try to do this dynamically:
ERROR : ‘PCLZIP_ERR_MISSING_FILE (-4) : File ’ array( array( PCLZIP_ATT_FILE_NAME => ‘data/file1.txt’ does not exist’
Here is what I have NOW, using the string instead of it being hard coded as in the example above:
$test_array="
array(
array( PCLZIP_ATT_FILE_NAME => 'data/file1.txt',
PCLZIP_ATT_FILE_NEW_FULL_NAME => 'newdir/newname.txt'
),
array( PCLZIP_ATT_FILE_NAME => 'data/file2.txt',
PCLZIP_ATT_FILE_NEW_FULL_NAME => 'data/newname2.txt'
),
),
";
$archive = new PclZip("rename_test.zip");
$list = $archive->create("[B]$test_array[/B]",
PCLZIP_OPT_ADD_PATH, 'Your Order',
PCLZIP_OPT_REMOVE_PATH, '157');
So the TOP bolded part works when hard coded. The second version doesn’t.
No parse errors, just the damn thing not treating the class functions the way I want. If I could fix this, it saves us from having to re-write THOUSANDS of mp3 files that have ugly non readable names (was done before I was hired) and would make my thanksgiving a lot more enjoyable.
Thanks for your time.
PS. For reference, just to be clear, *building the string in any way/shape or form - I can do that. Getting the script to read the string the same way it would read/process the hard coded code (bolded, in the first code example), that’s my dilemma. Thanks, again.