Jaswinder Posted March 29, 2013 Share Posted March 29, 2013 Note - my uploaded file goes into a folder name- songs i used the following code to upload :- In player.php <!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head> <body><form action="upload.php" method="post" enctype="multipart/form-data"><input type="file" name="i"/><input type="submit" value="Upload" /></form></body></html> In upload.php <? $i=$_FILES['i']['name'];copy($_FILES['i']['tmp_name'],"songs"."/".$i);$cn=mysql_connect("localhost","root","");$db=mysql_select_db("music",$cn);$a="insert into mp3 values('','$i')";$sql=mysql_query($a) or die(mysql_error);if($sql>=0){ echo "Successfully Entered";}else{ echo "failed";} ?><a href="show.php">show files</a> For downloading In show.php <?$cn=mysql_connect("localhost","root","");$db=mysql_select_db("music",$cn);$a="select * from mp3";$sql=mysql_query($a) or die(mysql_error);$n=mysql_num_rows($sql);if($n>0){while($f=mysql_fetch_array($sql)){?><table align="center" border="2" width="200" height="100"><td><a href="download.php?sno=<? echo $f['sno'];?>">Download</a></td></tr></table> <?} }else{echo 'No data';}?> In download.php<?php$download=$_GET['sno'];$cn=mysql_connect("localhost","root","");$db=mysql_select_db("music",$cn);$a="select songs from mp3 where sno='$download'";$sql=mysql_query($a) or die(mysql_error);$n=mysql_num_rows($sql);if($n>0){while($s=mysql_fetch_array($sql)){header("Content-type:audio/mpeg");header("Content-Disposition: attachment; filename='<? echo $s[songs]; ?>'"); i think here is the problem,.. not able to download files}} ?> Database name - musictable name - mp3fields - sno and songs Path to files - C:\xampp\htdocs\upload Path to songs folder where uploaded mp3 files go - C:\xampp\htdocs\upload\songs Link to comment Share on other sites More sharing options...
sircatsquid Posted March 29, 2013 Share Posted March 29, 2013 (edited) So I never seen anyone use copy to move the uploaded file to it's destination,if you followed any tutorial they would have used this function, very curious did youactually upload anything with copy to the destination?http://www.php.net/m...loaded-file.php Also you need to escape your user submitted data before having it in the query.http://www.php.net/m...cape-string.php You should look at mysqli since mysql is deprecated and will disaper from the near future.http://www.php.net/mysqli Edited March 29, 2013 by sircatsquid Link to comment Share on other sites More sharing options...
birbal Posted March 29, 2013 Share Posted March 29, 2013 You did not mention what is hppening instead, what does it show, errors. If you have outputs already made it should not send headers second time and show some error. does it show anything? make sure you have error enabled to show all level of error Link to comment Share on other sites More sharing options...
justsomeguy Posted April 1, 2013 Share Posted April 1, 2013 You're not actually sending the file data. You're sending headers that tell it what content type to expect, and what the filename is, but you don't actually send the file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now