Page 1 of 1

Need Help in uploading a file in php

Posted: Sun Apr 26, 2009 12:36 am
by puneet193128
hi,
I am making a website in which we can upload and download songs,i have written the code for uploading the song by selecting the path of the song in my system but the song is not being uploaded and error msg is shown.SO PLZ TEMME WHERE I AM GOING WRONG .here's my code for the page.The error msg shown is in the else part of the php code ,"there was an error uploading the file,plz try again".
i am using windows
This is CODE for the HTML PAGE

Code: Select all

 
<html>
<head>
<title>File Downloading</title>
</head>
<body bgcolor="#C0C0C0" topmargin="0" background="Background.bmp">
<form action="FileUpload.php" ENCTYPE="MULTIPART/FORM-DATA" method="post">
<div align="left">  
  <table width="75%" height="222" border="0">
    <tr>
      <td width="56%" height="76"><p align="right">&nbsp;</p>
      </td>
      <td width="44%">&nbsp;      </td>
    </tr>
    <tr>
      <td><div align="right">Select file to be uploaded </div>
      </td>
      <td><input name="fileupload" type="file" size="50">
      </td>
    </tr>
    <tr>
      <td><div align="right"><a href="home.php" target="_parent">Back</a></div></td>
      <td><input name="submit" type="submit" value="Upload" />
      </td>
    </tr>
  </table>
  <p>&nbsp;    </p>
</div>
</form>
</body>
</html>
 
 
this is the CODE FOR PHP PAGE.
 
 
<html>
  <head >
    <title>File Upload Example</title>
  </head>
  <body bgcolor="#C0C0C0" topmargin="0" background="Background.bmp">
    
    <hr/>
    <p>
 
<?php 
  $target_path ="uploads/";
  $target_path =$target_path.basename($_FILES['fileupload']['name']);
  
  if (move_uploaded_file($_FILES['fileupload']['tmp_name'],$target_path)){
  echo"the file". basename($_FILES['fileupload']['name'])."has been uploaded";
  }else{
  echo "there was an error uploading yhe file,please try again!";
  }      
 ?>
  
</p>
    <form name="form1" method="post" action="FileUpload.htm">
      <input type="submit" name="Submit" value="Back">
    </form>
    <p>&nbsp;    </p>
  </body>
</html>
 

Re: Need Help in uploading a file in php

Posted: Sun Apr 26, 2009 4:49 am
by Yossarian
I will point you to the advice I gave earlier today in a similar thread, set some basic error_reporting up for this script while you develop it, and start debugging each variable till you get to the bottom of the problem.