hi guys, i already have a working upload.php, now the problem is that the file cannot accept pdf files? but other than that, it works very well, what do you think should i do with this?

echo"<form enctype='multipart/form-data' action='fileRecs.php' method='POST'>";

echo "<input type='hidden' name='MAX_FILE_SIZE' value =1000000/>";

echo "Choose a file to upload: <input name='uploadedfile' type='file' /><br />";

echo "<input type='submit' name ='upload2' value='Upload File' /></form>"

$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$nameFile =  basename( $_FILES['uploadedfile']['name']);
$upload2 = $_POST['upload2'];


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
	{
		$buttonPress = 2;
		//establishing connection
		mysql_connect("localhost", "joomla_user", "joomla") or die(mysql_error());

		//connecting to the database
		mysql_select_db("db_php") or die(mysql_error());
		$result3 = mysql_query("SELECT * FROM files") or die(mysql_error());	

		mysql_query("INSERT INTO files (fileName) VALUES('$nameFile')") or die(mysql_error());

		echo "<script>alert('Uploading of file successful')</script>";
	}
	else
	{
		echo "There was an error uploading the file, please try again!";
	}

Dear friend

use the below sample code

<form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post">
   Last Name:<br /> <input type="text" name="name" value="" /><br />
   Class Notes:<br /> <input type="file" name="classnotes" value="" /><br />
   <p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>

<?php
   define ("FILEREPOSITORY","./");

   if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {

      if ($_FILES['classnotes']['type'] != "application/pdf") {
         echo "<p>Class notes must be uploaded in PDF format.</p>";
      } else {
         $name = $_POST['name'];
         $result = move_uploaded_file($_FILES['classnotes']['tmp_name'], FILEREPOSITORY."/$name.pdf");
         if ($result == 1) echo "<p>File successfully uploaded.</p>";
         else echo "<p>There was a problem uploading the file.</p>";
      } #endIF
   } #endIF
?>

Thanks

thanks sir! i already got the idea...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.