Jump to content

Not Sure If It's The Array Or The Syntax


refiking

Recommended Posts

I'm working on a zip archive script that works if I have no conditions. The second I check it against teh post data and try to render out a line, it doesn't work anymore. Not sure what I'm doing wrong. Here is the code with no conditions:


$files = array(
array('name'=>'file1', 'title'=>'file1', 'path' => 'file1.msi'),
array('name'=>'file2','title'=>'file2', 'path' => 'file2.msi'),
);

 

Here is what I'm trying to do:

 

$postfiles = $_POST;

if($postfiles['file1'] == 1){

$arrayme .= "array('name'=>'file1','title'=>'file1', 'path' => 'file1.msi'),";

}

if($postfiles['file2'] == 1){

$arrayme .= "array('name'=>'file2', 'title'=>'file2', 'path' => 'file2.msi'),";

}

$files = array(

 

$arrayme,

);

[code]

Link to comment
https://forums.phpfreaks.com/topic/271570-not-sure-if-its-the-array-or-the-syntax/
Share on other sites

Oops. I meant to enclose the code block

 

$postfiles = $_POST;[/font][/color]
if($postfiles['file1'] == 1){ [/font][/color]
$arrayme .= "array('name'=>'file1','title'=>'file1', 'path' => 'file1.msi'),";[/font][/color]
}[/font][/color]
if($postfiles['file2'] == 1){ [/font][/color]
$arrayme .= "array('name'=>'file2', 'title'=>'file2', 'path' => 'file2.msi'),";[/font][/color]
}[/font][/color]
$files = array([/font][/color]

$arrayme,[/font][/color]

);

not sure what you are trying to do exactly here, but maybe this will help...

 

$files = array();
for ($i = 1; $i <= $_POST['file_count']; $i++) {
    $files[] = array(
        'name' => $_POST['file' . $i . '-name'],
        'title' => $_POST['file' . $i . '-title'],
        'path' => $_POST['file' . $i . '-path'],
    );
}

What you wrote gave me an idea. Here is what I am trying to do basically...


$files = array();
if($postfiles['file1'] == 1){ 
$files[] = array('name'=>'file1','title'=>'file1', 'path' => 'file1.msi');
}
if($postfiles['file2'] == 1){ 
$files[] = array('name'=>'file2', 'title'=>'file 2', 'path' => 'file2.msi');
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.