hello there…
i’m a newbie in PHP, so i appreciate it much if anyone can help me with my system…
i have a form with upload file function…
uploaded file will be saved into C:/xampp/htdocs/onlineSystem/admin/attachments/…it’s file name will be saved in table ‘update’ in MySQL (this is to be used when displaying the uploaded file –> using a href)
the problem is that, when user clicks on the file name, the system looks at ‘admin’ folder, not the ‘attachments’ folder…
i think the problem is in the MySQL, because i only save it’s file name, not directory… (please correct me if i’m wrong…)
help me, anyone?
updateProjStat.php
<form name=“updateForm” action=“updateProjStatAction.php” enctype=“multipart/form-data” method=“post”>
<table>
<?php
echo “<tr>”;
echo “<td>Attach File</td>”;
echo “<td><input name=\“file\” type=\“file\” id=\“file\”></td>”;
echo “<tr>”;
?>
</table>
<?php
<input type=\“submit\” name=\“submitProjStat\” value=\“Submit Update\”/>
?>
</form>
updateProjStatAction.php
<?php
if(isset($_POST[‘submitProjStat’]))
{
$target = “C:/xampp/htdocs/onlineSystem/admin/attachments/”;
$target = $target . basename( $_FILES[‘file’][‘name’]);
$fileName=($_FILES[‘file’][‘name’]);
if (file_exists(“C:/xampp/htdocs/onlineSystem/admin/attachments/” . $_FILES[‘file’][‘name’]))
{
?> <script type=“text/javascript”>
alert(“Error
File already exists”);
history.go(-1);
</script>
<?php
}
else
{
move_uploaded_file($_FILES[‘file’][‘tmp_name’], $target);
$fileName = addslashes($fileName);
mysql_query(“INSERT INTO update
(fileName) VALUES (‘$fileName’)”) or die(mysql_error());
}
}
?>
updateLog.php
<?php
$qry2=mysql_query(“SELECT * FROM update
”);
$num2=mysql_num_rows($qry2);
if ($num2==0)
{ echo "<p>There is no update available for this project</p>"; }
else if ($num2>0)
{ echo "<table>";
echo "<tr><th>Attachment(s)</th></tr>";
while ($row2=mysql_fetch_array($qry2))
{ echo "<tr>";
echo "<td class=\\"tdCenter tdFont tdColor\\"><a href=\\"$row2[fileName]\\">$row2[fileName]</a></td></tr>";
echo "</tr>";
}
echo "</table>";
}
?>