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
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]

);

Edited by refiking
Link to comment
Share on other sites

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'],
    );
}

Link to comment
Share on other sites

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');
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.