Jump to content

Recommended Posts

Ok, So this is my upload script, What it dose it upload the track to the /Songs directory and then write the database with the DIR, The database part is fine, But when im trying to upload something with the script i keep getting the message "You cannot upload to the specified directory, please CHMOD it to 777.", But i did this and it still echos that message, Can somebody take a look for me?, Thanks in advance.

 

 

<?php include "Main/Database/base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta name="Description" content="Information architecture, Web Design, Web Standards." />
<meta name="Keywords" content="your, keywords" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Distribution" content="Global" />
<meta name="Author" content="Erwin Aligam - [email protected]" />
<meta name="Robots" content="index,follow" />

<link rel="stylesheet" href="images/MarketPlace.css" type="text/css" />

<LINK REL="SHORTCUT ICON"
       HREF="favicon.ico">

<title>Musicians Village - <?=$_SESSION['Username']?>'s Profile</title>

</head>

<body>

<!-- wrap starts here -->
<div id="wrap">

<!--header -->
<div id="header">			

	<div id="header-links">
	<p>
	<?php
		if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{
 	?>
    				<p>Logged in as: <a href="profile.php"><b><?=$_SESSION['Username']?></a></b> | Account: <?=$_SESSION['AccountType']?> | <a href="logout.php">Logout</a> </p>

	<?php
		}
		else
		{
	?>
			<p>Welcome <b>Guest</b>, Please <a href="login.php">Login</a> or <a href="register.php">Register</a></p>
	<?php
		}
	?>

    

	</p>		
	</div>		

<!--header ends-->					
</div>

<div id="header-photo"></div>		

<!-- navigation starts-->	
<div  id="nav">
	<ul>
		<li><a href="index.php">Home</a></li>
		<li><a href="login.php">Login</a></li>
		<li><a href="register.php">Register</a></li>			
		<li><a href="track.php?action=upload">Submit Track</a></li>
		<li><a href="track.php?action=listen">Listen To Tracks</a></li>
		<li><a href="/forums">Forums</a></li>
		<li><a href="contact.php">Contact</a></li>		
	</ul>
<!-- navigation ends-->	
</div>					

<!-- content-wrap starts -->
<div id="content-wrap" class="three-col"  >	

	<div id="sidebar">


		<h1>Sponsors</h1>
		<ul class="sidemenu">				
			<li><a href="index.html">Home</a></li>
			<li><a href="#TemplateInfo">Template Info</a></li>
			<li><a href="#SampleTags">Sample Tags</a></li>
			<li><a href="http://www.styleshout.com/">More Free Templates</a></li>	
			<li><a href="http://www.4templates.com/?aff=ealigam">Premium Templates</a></li>	
		</ul>	


	<!-- sidebar ends -->		
	</div>

	<div id="rightcolumn">

		<h1>Forum Stats</h1>
		<p>Top poster stuff here</p>

		<h1>*Newest track</h1>
		<p>it is here too! </p>				

	</div>


	<div id="main">

		<a name="TemplateInfo"></a>
	<?php
		if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{
 	?>
		<h1><?=$_SESSION['Username']?>'s Profile</h1>


		<p>

				<?php


					$Administrator = "Administrator";
					$AccountQurey = $_SESSION['AccountType'];

					$User = $_SESSION['Username'];
					$Email = $_SESSION['EmailAddress'];
					$AccTyp = $_SESSION['AccountType'];
					$AccountIP = $_SESSION['AccountIP'];


					$action = $_GET['action'];
					$Song = $_GET['song'];
					$Upload = "upload";
					$Password = "password";
					$Start = "";

					?>


			<?php
				if ($action == $Start) {
			?>
					<form action="track.php?action=upload" method="post" enctype="multipart/form-data">
					   <p>
						  <label for="SongName">Track Name:</label><input type="text" name="SongName" id="SongName" /><br />
						  <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
						  <button>Upload Track</button>
					   <p>
					</form>
					<?php
					$upload_path = "/Songs";
					echo $upload_path;
					}
					elseif($action == $Upload)
					{

										  // Configuration - Your Options
						  $allowed_filetypes = array('.mp3','.wma','.bmp','.png'); // These will be the types of file that will pass the validation.
						  $max_filesize = 52428888; // Maximum filesize in BYTES (currently 0.5MB).
						  $upload_path = "/Songs"; // The place the files will be uploaded to (currently a 'files' directory).

						  $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
						  $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.


								// Check if the filetype is allowed, if not DIE and inform the user.
							   if(!in_array($ext,$allowed_filetypes))
								  die('The file you attempted to upload is not allowed.');

							   // Now check the filesize, if it is too large then DIE and inform the user.
							   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
								  die('The file you attempted to upload is too large.');

							   // Check if we can upload to the specified path, if not DIE and inform the user.
							   if(!is_writable($upload_path))
								  die('You cannot upload to the specified directory, please CHMOD it to 777.');

							   // Upload the file to your specified path.
							   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
							   {
									$SongName = mysql_real_escape_string($_POST['SongName']);
									$SongAuthour = mysql_real_escape_string($_SESSION['Username']);
									$SongDIRR = "$upload_path/$filename";
									$SongDIR = mysql_real_escape_string($SongDIRR);


									$TrackQuery = mysql_query("INSERT INTO TrackUploads (TrackAuthor, TrackUrl, TrackName) VALUES('".$SongAuthour."', '".$SongDIR."', '".$SongName."')");

									$SongQurey = mysql_query("SELECT * FROM TrackUploads WHERE TrackUrl = '".$SongDIR."'");

									$row = mysql_fetch_array($SongQurey);
									$SongID = $row['id'];

									echo "<h1>Success</h1>";
									echo "<p>You have successfully uploaded your track!, You can listen to it <a href=\"track.php?song=$SongID\">Here</a>.</p>";
								}
								else
								{
									 echo 'There was an error during the file upload.  Please try again.'; // It failed .
								}
						} 		

					}
					?>
			<?php




			if(isset($_GET['song']))
			{
				if(is_numeric($_GET['song']))
				{
					// get the member id
					$memberID = (int) $_GET['song'];

					$memberIDinfo = mysql_real_escape_string($memberID);
					$checklogin = mysql_query("SELECT * FROM TrackUploads WHERE id = '".$memberIDinfo."'");
					$row = mysql_fetch_array($checklogin);

					$TrackUrl = $row['TrackUrl'];
					$TrackName = $row['TrackName'];
					$TrackAuthor = $row['TrackAuthor'];

					// Select only the row that matches memberID being requested, eg 123
					$query = "SELECT * FROM TrackUploads WHERE id = '$memberID'";
					$result = mysql_query($query);


					// check that the query returned one row, meaning a match was found
					if(mysql_num_rows($result) == 1)
					{
					?>
						<h1>Track : <?=$TrackName?></h1>
						<center>
							<embed src="<?=$TrackUrl?>" />
						</center>
						<br />
						<?php
						echo "<b>Artist:</b> $TrackAuthor";
						?>
						<br />
						<?php
						echo "<b>Track Name:</b> $TrackName";
						?>
						<br />

					<?php

					}
					// a match was not found. Display an error instead
					else
					{
						echo '<p style="color:red">Song does not exists</p>';
					}
				}

				// Either the member id was not declared or it was invalid. Display an error
				else
				{
					echo 'Invalid song id specified';
				}



			}
			else
			{
			?>
			<h1>Error</h1>
			<p>You need to be logged in to see your profile!</p>
			<?php
			}
			?>

				<br />

		</p>  


	</div>

<!-- content-wrap ends-->	
</div>

<!-- footer starts -->			
<div id="footer-wrap"><div id="footer">				

		<p>
		© 2006 <strong>Your Company</strong> | 
		Design by: <a href="http://www.styleshout.com/">styleshout</a> | 
		Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | 
		<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>

   		      

		<a href="index.html">Home</a> | 
   		<a href="index.html">Sitemap</a> | 
   	<a href="index.html">RSS Feed</a>
		</p>		

</div></div>
<!-- footer ends-->	

<!-- wrap ends here -->
</div>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/189095-problem-with-upload-script/
Share on other sites

Im on shared hosting at the moment i know my directory thought its : /home/chrismar/public_html/Websites/Music

 

Thats the script location the folder i want is:

 

/home/chrismar/public_html/Websites/Music/Songs

Ok, I tryed that and it seemed to have worked but the song is not in the /songs directory but it echoed success?

 

Updated Code:

 

<?php include "Main/Database/base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta name="Description" content="Information architecture, Web Design, Web Standards." />
<meta name="Keywords" content="your, keywords" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Distribution" content="Global" />
<meta name="Author" content="Erwin Aligam - [email protected]" />
<meta name="Robots" content="index,follow" />

<link rel="stylesheet" href="images/MarketPlace.css" type="text/css" />

<LINK REL="SHORTCUT ICON"
       HREF="favicon.ico">

<title>Musicians Village - <?=$_SESSION['Username']?>'s Profile</title>

</head>

<body>

<!-- wrap starts here -->
<div id="wrap">

<!--header -->
<div id="header">			

	<div id="header-links">
	<p>
	<?php
		if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{
 	?>
    				<p>Logged in as: <a href="profile.php"><b><?=$_SESSION['Username']?></a></b> | Account: <?=$_SESSION['AccountType']?> | <a href="logout.php">Logout</a> </p>

	<?php
		}
		else
		{
	?>
			<p>Welcome <b>Guest</b>, Please <a href="login.php">Login</a> or <a href="register.php">Register</a></p>
	<?php
		}
	?>

    

	</p>		
	</div>		

<!--header ends-->					
</div>

<div id="header-photo"></div>		

<!-- navigation starts-->	
<div  id="nav">
	<ul>
		<li><a href="index.php">Home</a></li>
		<li><a href="login.php">Login</a></li>
		<li><a href="register.php">Register</a></li>			
		<li><a href="track.php?action=upload">Submit Track</a></li>
		<li><a href="track.php?action=listen">Listen To Tracks</a></li>
		<li><a href="/forums">Forums</a></li>
		<li><a href="contact.php">Contact</a></li>		
	</ul>
<!-- navigation ends-->	
</div>					

<!-- content-wrap starts -->
<div id="content-wrap" class="three-col"  >	

	<div id="sidebar">


		<h1>Sponsors</h1>
		<ul class="sidemenu">				
			<li><a href="index.html">Home</a></li>
			<li><a href="#TemplateInfo">Template Info</a></li>
			<li><a href="#SampleTags">Sample Tags</a></li>
			<li><a href="http://www.styleshout.com/">More Free Templates</a></li>	
			<li><a href="http://www.4templates.com/?aff=ealigam">Premium Templates</a></li>	
		</ul>	


	<!-- sidebar ends -->		
	</div>

	<div id="rightcolumn">

		<h1>Forum Stats</h1>
		<p>Top poster stuff here</p>

		<h1>*Newest track</h1>
		<p>it is here too! </p>				

	</div>


	<div id="main">

		<a name="TemplateInfo"></a>
	<?php
		if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{
 	?>
		<h1><?=$_SESSION['Username']?>'s Profile</h1>


		<p>

				<?php


					$Administrator = "Administrator";
					$AccountQurey = $_SESSION['AccountType'];

					$User = $_SESSION['Username'];
					$Email = $_SESSION['EmailAddress'];
					$AccTyp = $_SESSION['AccountType'];
					$AccountIP = $_SESSION['AccountIP'];


					$action = $_GET['action'];
					$Song = $_GET['song'];
					$Upload = "upload";
					$Password = "password";
					$Start = "";

					?>


			<?php
				if ($action == $Start) {
			?>
					<form action="track.php?action=upload" method="post" enctype="multipart/form-data">
					   <p>
						  <label for="SongName">Track Name:</label><input type="text" name="SongName" id="SongName" /><br />
						  <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
						  <button>Upload Track</button>
					   <p>
					</form>
					<?php
					$upload_path = "/home/chrismar/public_html/Websites/Music/Songs";
					echo $upload_path;
					}
					elseif($action == $Upload)
					{

										  // Configuration - Your Options
						  $allowed_filetypes = array('.mp3','.wma','.bmp','.png'); // These will be the types of file that will pass the validation.
						  $max_filesize = 52428888; // Maximum filesize in BYTES (currently 0.5MB).
						  $upload_path = "/home/chrismar/public_html/Websites/Music/Songs"; // The place the files will be uploaded to (currently a 'files' directory).

						  $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
						  $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.


								// Check if the filetype is allowed, if not DIE and inform the user.
							   if(!in_array($ext,$allowed_filetypes))
								  die('The file you attempted to upload is not allowed.');

							   // Now check the filesize, if it is too large then DIE and inform the user.
							   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
								  die('The file you attempted to upload is too large.');

							   // Check if we can upload to the specified path, if not DIE and inform the user.
							   if(!is_writable($upload_path))
								  die('You cannot upload to the specified directory, please CHMOD it to 777.');

							   // Upload the file to your specified path.
							   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
							   {
									$SongName = mysql_real_escape_string($_POST['SongName']);
									$SongAuthour = mysql_real_escape_string($_SESSION['Username']);
									$SongDIRR = "$upload_path/$filename";
									$SongDIR = mysql_real_escape_string($SongDIRR);


									$TrackQuery = mysql_query("INSERT INTO TrackUploads (TrackAuthor, TrackUrl, TrackName) VALUES('".$SongAuthour."', '".$SongDIR."', '".$SongName."')");

									$SongQurey = mysql_query("SELECT * FROM TrackUploads WHERE TrackUrl = '".$SongDIR."'");

									$row = mysql_fetch_array($SongQurey);
									$SongID = $row['id'];

									echo "<h1>Success</h1>";
									echo "<p>You have successfully uploaded your track!, You can listen to it <a href=\"track.php?song=$SongID\">Here</a>.</p>";
								}
								else
								{
									 echo 'There was an error during the file upload.  Please try again.'; // It failed .
								}
						} 		

					}
					?>
			<?php




			if(isset($_GET['song']))
			{
				if(is_numeric($_GET['song']))
				{
					// get the member id
					$memberID = (int) $_GET['song'];

					$memberIDinfo = mysql_real_escape_string($memberID);
					$checklogin = mysql_query("SELECT * FROM TrackUploads WHERE id = '".$memberIDinfo."'");
					$row = mysql_fetch_array($checklogin);

					$TrackUrl = $row['TrackUrl'];
					$TrackName = $row['TrackName'];
					$TrackAuthor = $row['TrackAuthor'];

					// Select only the row that matches memberID being requested, eg 123
					$query = "SELECT * FROM TrackUploads WHERE id = '$memberID'";
					$result = mysql_query($query);


					// check that the query returned one row, meaning a match was found
					if(mysql_num_rows($result) == 1)
					{
					?>
						<h1>Track : <?=$TrackName?></h1>
						<center>
							<embed src="<?=$TrackUrl?>" />
						</center>
						<br />
						<?php
						echo "<b>Artist:</b> $TrackAuthor";
						?>
						<br />
						<?php
						echo "<b>Track Name:</b> $TrackName";
						?>
						<br />

					<?php

					}
					// a match was not found. Display an error instead
					else
					{
						echo '<p style="color:red">Song does not exists</p>';
					}
				}

				// Either the member id was not declared or it was invalid. Display an error
				else
				{
					echo 'Invalid song id specified';
				}



			}
			else
			{
			?>
			<h1>Error</h1>
			<p>You need to be logged in to see your profile!</p>
			<?php
			}
			?>

				<br />

		</p>  


	</div>

<!-- content-wrap ends-->	
</div>

<!-- footer starts -->			
<div id="footer-wrap"><div id="footer">				

		<p>
		© 2006 <strong>Your Company</strong> | 
		Design by: <a href="http://www.styleshout.com/">styleshout</a> | 
		Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | 
		<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>

   		      

		<a href="index.html">Home</a> | 
   		<a href="index.html">Sitemap</a> | 
   	<a href="index.html">RSS Feed</a>
		</p>		

</div></div>
<!-- footer ends-->	

<!-- wrap ends here -->
</div>

</body>
</html>

$upload_path . $filename

You will find that the file is in the .. ../Music folder and it has a name that starts with 'Songs', something like Songssomething.ext because there is no / separator between the path and the filename.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.