tail Posted January 10, 2010 Share Posted January 10, 2010 I'm trying to create a script to add music to a database. Currently I'm using ID3tag to get the ID3 information from the MP3. The way I have the form set up is like this: When Auto-Fill is clicked, the script detects it and the ID3 information is echoed to the form, like this: However, the file is obviously no longer in the input. I tried to overcome this by making a hidden form field with a value of $_FILES['file']['tmp_name'] but it didn't work. How can I overcome this? Thanks for any help in advance! Quote Link to comment https://forums.phpfreaks.com/topic/187983-keep-_files-info-after-submit/ Share on other sites More sharing options...
RaythMistwalker Posted January 10, 2010 Share Posted January 10, 2010 if you show your code we should be able to help you better. Quote Link to comment https://forums.phpfreaks.com/topic/187983-keep-_files-info-after-submit/#findComment-992455 Share on other sites More sharing options...
tail Posted January 10, 2010 Author Share Posted January 10, 2010 if (!isset($_POST['submit'])) { if (!isset($_POST['autofill'])) { echo '<span style="font-size:18pt"><a href="index.php">Administration Area</a> > <a href="music.php">Music</a> > Add</span></td></tr></table></div></td></tr><tr><td>Â </td></tr><tr><td align="center"><form enctype="multipart/form-data" action="music.php?act=add" method="post"><table align="center"><tr><td><span class="title">File</span></td><td><input type="file" name="file" />Â <input type="submit" name="autofill" value="Auto-Fill"></td></tr><tr><td valign="top"><span class="title">Title</span></td><td><input type="text" name="title" style="width:347px;" maxlength="35" /></td></tr><tr><td valign="top"><span class="title">Artist</span></td><td><input type="text" name="artist" style="width:347px;" maxlength="35" /></td></tr><tr><td valign="top"><span class="title">Genre</span></td><td><input type="text" name="title" style="width:347px;" maxlength="30" /></td></tr><tr><td valign="top"><span class="title">Quality</span></td><td><input type="text" name="quality" style="width:347px;" maxlength="20" /></td></tr><tr><td valign="top"><span class="title">Length</span></td><td><input type="text" name="min" maxlength="2" size="1" />:<input type="text" name="sec" size="1" maxlength="2" /></td></tr><tr><td><span class="title">Comments</span></td><td><input type="checkbox" name="comments" value="1" checked /></td></tr><tr><td colspan="2" align="center"><input type="submit" name="submit" value="Add Song" />Â <input type="reset" value="Clear" /></td></tr></table></form><center><a href="javascript:history.go(-1)">Go back</a></center>'; } else { require_once('/var/www/getid3/getid3.php'); $getid3 = new getID3; $file=$_FILES['file']['tmp_name']; $id3 = $getid3->analyze($file); getid3_lib::CopyTagsToComments($id3); $cbr=($id3['audio']['bitrate_mode'] == 'cbr') ? ' CBR' : ''; $id3['audio']['bitrate']=round($id3['audio']['bitrate']/1000).'kbps'.$cbr; $length=explode(':',$id3['playtime_string']); echo '<span style="font-size:18pt"><a href="index.php">Administration Area</a> > <a href="music.php">Music</a> > Add</span></td></tr></table></div></td></tr><tr><td>Â </td></tr><tr><td align="center"><form enctype="multipart/form-data" action="music.php?act=add" method="post"><table align="center"><tr><td><span class="title">File</span></td><td><input type="file" name="file" />Â <input type="submit" name="autofill" value="Auto-Fill"></td></tr><tr><td valign="top"><span class="title">Title</span></td><td><input type="text" name="title" value="'.$id3['comments_html']['title'][0].'" style="width:347px;" maxlength="35" /></td></tr><tr><td valign="top"><span class="title">Artist</span></td><td><input type="text" name="artist" value="'.$id3['comments_html']['artist'][0].'" style="width:347px;" maxlength="35" /></td></tr><tr><td valign="top"><span class="title">Genre</span></td><td><input type="text" name="genre" value="'.$id3['comments_html']['genre'][0].'" style="width:347px;" maxlength="30" /></td></tr><tr><td valign="top"><span class="title">Quality</span></td><td><input type="text" name="quality" value="'.$id3['audio']['bitrate'].'" style="width:347px;" maxlength="20" /></td></tr><tr><td valign="top"><span class="title">Length</span></td><td><input type="text" name="min" size="1" maxlength="2" value="'.$length[0].'" />:<input type="text" name="sec" size="1" maxlength="2" value="'.$length[1].'" /></td></tr><tr><td><span class="title">Comments</span></td><td><input type="checkbox" name="comments" value="1" checked /></td></tr><tr><td colspan="2" align="center"><input type="hidden" name="tmp" value="'.$_FILES['file']['tmp_name'].'" /><input type="submit" name="submit" value="Add Song" />Â <input type="reset" value="Clear" /></td></tr></table></form><center><a href="javascript:history.go(-1)">Go back</a></center>'; } } else { $comments = (isset($_POST['comments'])) ? '1' : '0'; $errors=0; if (empty($_POST['title'])) { $errormsg='Fill in the "Title" field'; $errors++; } if (strlen($_POST['title']) > 35) { if ($errormsg) { $errormsg = $errormsg . '<br />Shorten the "Title" field to under 35 characters'; } else { $errormsg = 'Shorten the "Title" field to under 35 characters'; } $errors++; } if (empty($_POST['genre'])) { if ($errormsg) { $errormsg = $errormsg . '<br />Add a genre'; } else { $errormsg = 'Add a genre'; } $errors++; } if (strlen($_POST['genre']) > 30) { if ($errormsg) { $errormsg = $errormsg . '<br />Shorten the "Genre" field to under 30 characters'; } else { $errormsg = 'Shorten the "Genre" field to under 30 characters'; } $errors++; } if (empty($_POST['min']) || empty($_POST['sec'])) { if ($errormsg) { $errormsg = $errormsg . '<br />Fill in both "Length" fields'; } else { $errormsg = 'Fill in both "Length" fields'; } $errors++; } if (empty($_POST['quality'])) { if ($errormsg) { $errormsg = $errormsg . '<br />Add a quality'; } else { $errormsg = 'Add a quality'; } $errors++; } if (strlen($_POST['quality']) > 20) { if ($errormsg) { $errormsg = $errormsg . '<br />Shorten the "Quality" field to under 20 characters'; } else { $errormsg = 'Shorten the "Genre" field to under 20 characters'; } $errors++; } if (file_exists($_POST['tmp'])) { if (mime_content_type($_POST['tmp']) != 'audio/mpeg') { if ($errormsg) { $errormsg = $errormsg . '<br />The song must be a valid MP3'; } else { $errormsg = 'The song must be a valid MP3'; } $errors++; } } else { if ($errormsg) { $errormsg = $errormsg . '<br />Could not locate song'; } else { $errormsg = 'Could not locate song'; } $errors++; } if ($errors==0) { mysql_connect($dbhost,$dbusername,$dbuserpass) or die("Unable to connect to database"); @mysql_select_db("music") or die("Unable to select database"); $title = mysql_real_escape_string(ltrim(rtrim(htmlentities($_POST['title'])))); $text = mysql_real_escape_string(ltrim(rtrim(nl2br(htmlentities(stripslashes($_POST['body'])))))); //$query = mysql_query("INSERT INTO `tracks` VALUES('','".$_SESSION['id']."','".time()."','".$title."','".$text."','".$comments."')"); if ($query) { echo '<span style="font-size:18pt"><a href="index.php">Administration Area</a> > <a href="music.php">Music</a> > Add</span></td></tr></table></div></td></tr><tr><td>Â </td></tr><tr><td align="center">The songs was posted successfully. The page should automatically refresh in 2 seconds. <a href="music.php">If not, click here</a><meta http-equiv="refresh" content="2;URL=music.php"></td></tr></table>'; } else { echo '<span style="font-size:18pt"><a href="index.php">Administration Area</a> > <a href="music.php">Music</a> > Add</span></td></tr></table></div></td></tr><tr><td>Â </td></tr><tr><td align="center">There was an error adding your song. Please try again later. <a href="music.php">Go back</a></td></tr></table>'; } } else { $check = ($_POST['comments'] == 1) ? ' checked' : ''; echo '<span style="font-size:18pt"><a href="index.php">Administration Area</a> > <a href="music.php">Music</a> > Add</span></td></tr></table></div></td></tr><tr><td>Â </td></tr><tr><td colspan="2" align="center">'.$errormsg.'</td></tr><tr><td align="center"><form enctype="multipart/form-data" action="music.php?act=add" method="post"><table align="center"><tr><td><span class="title">File</span></td><td><input type="file" name="file" />Â <input type="submit" name="autofill" value="Auto-Fill"></td></tr><tr><td valign="top"><span class="title">Title</span></td><td><input type="text" name="title" style="width:347px;" value="'.$_POST['title'].'" maxlength="35" /></td></tr><tr><td valign="top"><span class="title">Artist</span></td><td><input type="text" name="artist" style="width:347px;" value="'.$_POST['artist'].'" maxlength="35" /></td></tr><tr><td valign="top"><span class="title">Genre</span></td><td><input type="text" name="title" style="width:347px;" value="'.$_POST['genre'].'" maxlength="30" /></td></tr><tr><td valign="top"><span class="title">Quality</span></td><td><input type="text" name="quality" style="width:347px;" value="'.$_POST['quality'].'" maxlength="20" /></td></tr><tr><td valign="top"><span class="title">Length</span></td><td><input type="text" name="min" size="1" value="'.$_POST['min'].'" maxlength="2" />:<input type="text" name="sec" size="1" value="'.$_POST['sec'].'" maxlength="2" /></td></tr><tr><td><span class="title">Comments</span></td><td><input type="checkbox" name="comments" value="1"'.$check.' /></td></tr><tr><td colspan="2" align="center"><input type="submit" name="submit" value="Add Song" />Â <input type="reset" value="Clear" /></td></tr></table></form><center><a href="javascript:history.go(-1)">Go back</a></center>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/187983-keep-_files-info-after-submit/#findComment-992461 Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2010 Share Posted January 11, 2010 The contents of the type='file' input box can ONLY BE SET by the browser. You cannot set it using javascript and you cannot set it using a value="..." attribute in the HTML. Â IF you could do what you are attempting, it would result in the file being uploaded to the server twice. Quote Link to comment https://forums.phpfreaks.com/topic/187983-keep-_files-info-after-submit/#findComment-992471 Share on other sites More sharing options...
tail Posted January 11, 2010 Author Share Posted January 11, 2010 Ok. I don't know very much about AJAX, but is there a way the script could achieve the desired result using it? Quote Link to comment https://forums.phpfreaks.com/topic/187983-keep-_files-info-after-submit/#findComment-992478 Share on other sites More sharing options...
tail Posted January 11, 2010 Author Share Posted January 11, 2010 Is there a way that could work? Again, I don't know AJAX or how it works, but it seems that perhaps I could send the $_FILES['file']['tmp'] variable to an external script that gets the ID3 information from the ID3 class, and then returns the values to the form. Yes? No? Please help. Quote Link to comment https://forums.phpfreaks.com/topic/187983-keep-_files-info-after-submit/#findComment-993057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.