$_POST for multiple files won't insert into DB table
Posted: Sun Mar 28, 2010 5:29 pm
I have a PHP file that inserts input data into a table in mySql database. The name of the table is called "user_audio". I am having difficulty getting an image file to be stored into the table.
Image file php = "[audio_screenshot]"
input field = "<li><input type="file" name="audio_screenshot" /></li>"
I'm using the $uploadArtfile php function
Here's the code I have:
Image file php = "[audio_screenshot]"
input field = "<li><input type="file" name="audio_screenshot" /></li>"
I'm using the $uploadArtfile php function
Here's the code I have:
Code: Select all
<?php
//activates the session
session_start();
// process form
if ($_POST['submit']) {
include_once ("config.php");
$uploadDir = '/home/content/k/w/a/kwansahmadani/html/audio/music/'; // YOUR directory here
// The next lines add the directory of the artist and the album
$newDirectory = $uploadDir . $_POST['audio_artist']; // adds the artist/album to the path
echo $newDirectory;
if( mkdir( $newDirectory , 0777 ) )
{
// print success information
echo 'Album folder was created!';
echo '<br>folder: <a href="' . $newDirectory . '">' . $newDirectory. '</a>';
$newDirectory = $uploadDir . $_POST['audio_artist'] . '/' . $_POST['audio_album'] ; // adds the artist/album to the path
if(mkdir( $newDirectory , 0777)){
echo 'Artist folder was created!';
echo '<br>folder: <a href="' . $newDirectory . '">' . $newDirectory. '</a>';
} // end if create artist folder
}else{
// print error information
echo 'an error occurred attempting to create folder';
echo '<br>newDirectory: ' . $newDirectory;
echo '<br>php_errormsg: ' . $php_errormsg;
} // end if rs
echo "audio content and name" . $_FILES['audio_content']['name']; // print the file name
echo "<br />audio content without name" . $_FILES['audio_content']; // print the file name
echo "<br />audio content and tmp name" . $_FILES['audio_content']['tmp_name']; // print the file name
$uploadFile = $newDirectory . '/' . $_FILES['audio_content']['name']; // this will be the NEW complete path.
$webPath = "http://meta5player.com/audio/music/" . $_POST['audio_artist'] . '/' . $_POST['audio_album'] . '/' . $_FILES['audio_content']['name'] ; // web path
//cover art starts here
$uploadArtDir = '/home/content/k/w/a/kwansahmadani/html/audio/asset/photo/'; // YOUR directory here
$artDirectory = $uploadArtDir . $_POST['audio_screenshot']; // this will be the NEW complete path.
$uploadArtFile = $artDirectory . '/' . $_FILES['audio_screenshot']['name'];
$webPathArt = "http://meta5player.com/audio/asset/photo/" . $_FILES['audio_screenshot']; // web path
echo '<br />';
echo 'image can be found here: <a href="' .$artDirectory . '">' .$artDirectory. '</a>';
echo '<br />';
if (move_uploaded_file($_FILES['audio_content']['tmp_name'], $uploadFile)) {
$sql = "INSERT INTO user_audio ( user_id, audio_content, audio_title, audio_description, audio_album, audio_number, audio_time, audio_label, audio_artist, audio_screenshot ) VALUES ('$_SESSION[user_id]', '$webPath', '$_POST[audio_title]', '$_POST[audio_description]', '$_POST[audio_album]', '$_POST[audio_number]', '$_POST[audio_time]', '$_POST[audio_label]', '$_POST[audio_artist]', '$_FILES[audio_screenshot]')";
if (mysql_query($sql)) {
echo "<a href = \"$webPath\">$_POST[audio_title]</a> ".'has been successfully uploaded<br />';
echo "$_FILES[audio_screenshot]";
echo "<br />$_FILES[audio_screnshot]</a> ".'is the cover art file.<br />';
} else {
echo mysql_error();
}
} else {
echo 'file not uploaded';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>META5 :: NEW AUDIO</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Kwansah Madani Interactive" />
<style type="text/css">
body {background: #FFFFFF; width: 95%;}
#container {margin: 10px auto; text-align: center; width: 100%;}
.audio_page {text-align: left;}
.audio {width: 400px; height: 400px; padding: 15px; border: 1px solid #CCCCCC; border-bottom: none;font-family: helvetica, arial, times new roman; font-size: 11px; font-weight: bold;}
.f-left {float: left;}
.f-right {float: right;}
.audio ul {margin: 0px; padding: 0px; list-style-type: none; list-style-image: none; line-height: 2.5em; width: 140px;}
.audio ul li {display: block;}
.button {width: 400px; padding: 15px; text-align: center; border: 1px solid #CCCCCC; border-top: none;}
</style>
</head>
<body>
<div id="container">
<div class="audio_page">
<!-- audio form -->
<form enctype="multipart/form-data" action = "kwan.audio.php" method = "POST">
<input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
<div class="audio">
<span class="f-left;">
<ul style="margin: 0px; padding: 0px; list-style-type: none; list-style-image: none; line-height: 2.5em; width: 120px; float: left; display: block;">
<li>ARTIST:</li>
<li>ALBUM:</li>
<li>RECORD LABEL:</li>
<li>COVER ART:</li>
<li>TRACK NAME:</li>
<li>FILE:</li>
<li>TRACK #:</li>
<li>TIME:</li>
<li>DESCRIPTION:</li>
</ul>
</span>
<span class="f-left">
<ul style="margin: 0px; padding: 0px; list-style-type: none; list-style-image: none; line-height: 2.5em; width: 120px; float: left; display: block;">
<li><input type="text" name="audio_artist" /></li>
<li><input type="text" name="audio_album" /></li>
<li><input type="text" name="audio_label" /></li>
<li><input type="file" name="audio_screenshot" /></li>
<li><input type="text" name="audio_title" /></li>
<li><input type="file" name="audio_content" /></li>
<li><input type="text" name="audio_number" /></li>
<li><input type="text" name="audio_time" /></li>
<li><textarea rows="10" cols="26" name="audio_description" /></textarea></li>
</ul>
</span>
</div>
<div class="button">
<input type="submit" name="submit" value="Submit">
</div>
</form>
<!-- end audio form -->
</div>
</div>
</body>
</html>