hi to all... i try to use this code for upload pdf file.. it's work when i upload two times with same name. i want it's work with one time upload then success. anyone can help me? this is my 1st assignment in my job.. i must pass for this to get this job.. 🙁 please....
- configuration or coding error?
- how to assign the file upload to specific folder?
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>
<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'])) {
echo $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
?>