Hey, sorry to bother you guys. I'm trying to use PHP to upload music to my server. (it's currently set to image files because I have no audio files on my laptop and I need to test the script). However, I keep getting the error whenever I submit the form. It stores the data in the database but doesnt store the file on the server. And since adding the enctype to the form, all the $_POST variables are empty. $NP and reputation for anyone who can solve this problem or suggest a script which will enable me to upload a music file with another field for the title of the file.
Is the script at the moment
Thanks in advance.
PHP:
<?
session_start();
if (!isset($_SESSION['logged_in'])) {
echo '<script>alert("You must be logged in to view this page.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
include("config.php");
include("includes/userinfo.php");
if ($artist == "") {
echo "<p>You must be registered as an artist to view this page.</p> <p><a href='index.php'>Return</a></p>"; }
$pagetitle = "Upload a file";
if ($_POST['submit'])
{
$file=addslashes($_POST['userfile']);
$title=addslashes($_POST['title']);
if ( empty($file) || empty($title) )
{
echo '<script>alert("One or more fields were left empty, please try again.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
$query = "INSERT INTO files (id, title, file, artist, submit) VALUES
('', '$title', '$file', '$artist', '" . $_SESSION['logged_in'] . "')";
$results = mysql_query($query);
echo mysql_error();
################################################
$path = "uploads/";
$max_size = 200000;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {}
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {}
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
################################################
if ($results && $res)
{
include("head.php");
echo "<h1>Success</h1><p>The file was successfully uploaded.</p><p><a href='artistarea.php'>Return</a>";
include("foot.php");
}
else
{
include("head.php");
echo "<h1>Error</h1><p>There was an error uploading the file, please try again or <a href='contact.php'>contact</a> the administrator.</p>";
include("foot.php");
}
mysql_close();
}
else
{
include("head.php");
echo "
<h1>Upload a song/video</h1>
<form method='post' action='upload.php'>
<table width='447' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td height='44'>File</td>
<td><input type='file' name='userfile' class='inputbox'></td>
</tr>
<tr>
<td height='48'>Title of song/video </td>
<td><input type='text' name='title' class='inputbox'></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='submit' value='Submit'></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
";
include("foot.php");
}
?>
Is the script at the moment
Thanks in advance.





