1,105,344 Community Members

php input arrays question

Member Avatar
florin1
Newbie Poster
6 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello guys. I made a form with 3 inputs (song name 1, song name 2 and album name). When i submit this form it calls a php script like this one:

<?php
$song1 = $_POST['song1'];
$song2 = $_POST['song2'];
$album = $_POST['album'];

$output = shell_exec('D:\\apache\\htdocs\\test\\mp3wrap\\mp3wrap.exe '.$album.' '.$song1.' '.$song2.'');
echo "<pre>$output</pre>";

?>

This merges the 2 song files into 1 song. I can add in the form more song name inputs, but i want php to automaticaly create arrays from inputs and add them to the shell_exec command. So how can i make the php script add the input arrays without me manually writing $song3 = $_POST; $song4 = $_POST;...etc?
Thanks

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

Store the song names in an array when fed from the form. E.g.:

<form method="post" action="">
    <!-- field labels and submit button excluded for simplicity -->

    <input type="text" name="song[]" />
    <input type="text" name="song[]" />
    <input type="text" name="song[]" />
    <input type="text" name="song[]" />
    <input type="text" name="song[]" />
    <input type="text" name="song[]" />
    <!-- etc... -->

    <input type="text" name="album" />
</form>

Then after form submission...

$songs = isset($_POST['song']) ? $_POST['song'] : array();
$album = isset($_POST['album']) ? $_POST['album'] : '';

// Remove empty song fields and implode
$songs = array_filter($songs);
$songs = implode(' ', $songs);

// You should make sure you validate values before executing them on your server
$output = shell_exec("D:\\apache\\htdocs\\test\\mp3wrap\\mp3wrap.exe {$album} {$songs}");

R.

Member Avatar
florin1
Newbie Poster
6 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thank you very much, it works...but how can i add a path to the mp3 folder? because $song will be in a folder called mp3 an my command line would look like this:
mp3wrap.exe album_name path/to/song1 path/to/song2 path/to/song3

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article