Can you give me a code so my users can upload an MP3 file to there folder on my social network. i can't seem to get this one to work.
<?php
session_start(); // Must start session first thing
/*
Created By Adam Khoury @ www.flashbuilding.com
-----------------------June 20, 2008-----------------------
*/
// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '<a href="member_profile.php?id=' . $userid . '">Profile</a> •
<a href="../index.php">Account</a> •
<a href="logout.php">Log Out</a>';
} else {
echo 'Please <a href="login.php">log in</a> to access your account';
exit();
}
?>
<?php
session_start(); // Must start session first thing
/*
Created By Adam Khoury @ www.flashbuilding.com
-----------------------June 20, 2008-----------------------
*/
// Here we run a login check
if (!isset($_SESSION['id'])) {
echo 'Please <a href="login.php">log in</a> to access your account';
exit();
}
// Place Session variable 'id' into local variable
$id = $_SESSION['id'];
// Process the form if it is submitted
if ($_FILES['uploadedfile']['tmp_name'] != "") {
// Run error handling on the file
// Set Max file size limit to somewhere around 120kb
$maxfilesize = 120000;
// Check file size, if too large exit and tell them why
if($_FILES['uploadedfile']['size'] > $maxfilesize ) {
echo "<br /><br />Your song was too long. Must be 100kb or less";
unlink($_FILES['uploadedfile']['tmp_name']); include_once 'edit_music.php';
// Check file extension to see if it is .mp3 or .wav, if not exit and tell them why
} else if (!preg_match("/\.(mp3|wav)$/i", $_FILES['uploadedfile']['name'] ) ) { $success =
"<br /><br />Your song was not .wav or .MP3 and it must be one of those two formats, please<br />
<a href=\"edit_music.php\">click here</a> to try again";
unlink($_FILES['uploadedfile']['tmp_name']);include_once 'edit_music.php';
// If no errors on the file process it and upload to server
} else { $success =
// Rename the song
$newname = "song1";
// Set the direntory for where to upload it, use the member id to hit their folder
// Upload the file
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "../memberFiles/$id/".$newname)) {
$success = '<big style="font-weight: bold; font-style: italic;"><span style="color: rgb(78, 254, 112);">
Success, the Song has been uploaded and will display to visitors!<br>
';include_once 'edit_music.php';
} else {
$success = '<big style="font-weight: bold; font-style: italic;"><span style="color: rgb(78, 254, 112);">There was an error uploading the file, please try again. If it continually fails, contact us by email. <br /><br />
<a href="../index.php">Click here</a> to return to your profile edit area';include_once 'edit_music.php';
}
} // close else after file error checks
} // close if post the form
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<LINK REL="SHORTCUT ICON" HREF="http://harborcityrecords.com/hcrindienetwork/graphics/faveicon.gif">
<title><?php echo "$username"; ?>'s Music Edit</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../default.css">
<style>
#bodydiv
{
height: 600px;
}
</style>
</head>
<body>
<div id="container">
<div id="content">
<?php include 'profileheaderimages/profileheader.php'; ?>
<div id="navbar">
<?php include('menu/menu.php'); ?>
</div>
<div id="bodydiv">
<table style="width: 870px; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="text-align: center; vertical-align: top; width: 120px;"><script type="text/javascript"><!--
google_ad_client = "pub-0568620827775779";
/* side bars */
google_ad_slot = "2933541440";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></td>
<td style="text-align: center; vertical-align: top; width: 617px;">
<script type="text/javascript">
<!-- Form Validation -->
function validate_form ( ) {
valid = true;
if ( document.form.uploadedfile.value == "" ) {
alert ( "Please browse for a file on your PC and place it" );
valid = false;
}
return valid;
}
<!-- Form Validation -->
</script>
</head>
<body>
<div align="center">
<h3>
Upload your music files here <br />
</h3><?php print "$success"; ?>
<br />
</h3>
</div>
<table border="2" align="center" cellpadding="5" cellspacing="5">
<form action="edit_music2.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return validate_form ( );">
<tr>
<td colspan="2">
<object type="application/x-shockwave-flash" data="musicplayer/dewplayer-playlist.swf" width="240" height="200" id="dewplayer" name="dewplayer">
<param name="wmode" value="transparent" />
<param name="movie" value="musicplayer/dewplayer-playlist.swf" />
<param name="flashvars" value="showtime=true&autoreplay=true&xml=musicplayer/playlist.xml" />
</object>
</td>
</tr>
<tr>
<td colspan="2"><input name="uploadedfile" type="file" /></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Upload Image" />
</div></td>
</tr>
</form>
</table>
</td>
<td style="width: 120px; text-align: center; vertical-align: top;"><script type="text/javascript"><!--
google_ad_client = "pub-0568620827775779";
/* side bars */
google_ad_slot = "2933541440";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></td>
</tr>
</tbody>
</table>
</div>
<div id="footer">
</div>
<div id="underfooter">
<p class="footer">© 2011 HCR Network is a subsidary of Harbor City Records LLC. All Rights Reserved.<br>
<a style="color: rgb(204, 0, 0);" href="../problemreport.php" target="_blank"><small>Report A Problem<small></a></p>
<div style="position:relative; top: -793px; right: 45px; text-align: right;"><?php echo $toplinks; ?></div>
</div>
</div>
</div>
</body>
</html>