Uploading files
Posted: Mon May 27, 2002 3:55 pm
I'm trying to create a form for a news portal where a user can either upload text into a database, or upload a PDF file to the server into a directory. They can only do one or the other. Here's what I have:
The addAnnouncement() is just a simple function to addslashes to the text and upload the text from the form into a database using an INSERT statement.
For some reason, the script is compleyely ignoring my if{} statement, and no matter what I do, either try to type in text in the text field or try to upload a file, the script always ends up du ping the error text: "There was an error uploading your file! <br>Please make sure you are only uploading only pdf files! Other file types will be rejected." I've used pretty much this same script on other wesbites, but haven't had this many problems. I only want user to be able to upload >pdf files, nothing else, hence the if(!in_array(...) statement. If the file extension is not ".pdf" or ".PDF", then the file gets rejected and nothing happens.
I was hoping someone could help me here, maybe suggest a better way of doing this or pointing me in the proper direction as to where I may find a better example to edit to my own needs.
thanks
Code: Select all
if (!isset($file))
{
addAnnouncement($announcementName,$announcementDescr,$announcementText,$caoID);
echo "<p align="center"></p><font face="Arial, Helvetica, sans-serif" size="2">Your announcement has been successfully uploaded. Thank you!</font></p>";
}
elseif (isset($file))
{
$formats = array('pdf','PDF');
if(!in_array(strtolower(substr($file_name,-3)),$formats))
{
echo "<font face="arial,helvetica, sans serif" size="2" color="#000000"><b>There was an error uploading your file! <br>Please make sure you are only uploading only pdf files! Other file types will be rejected.</b></font>";
}
else
{
copy($file, "../pdf/$file_name");
unlink($file);
$announcementText = $file_name;
addAnnouncement($announcementName,$announcementDescr,$announcementText,$caoID);
echo "<p align="center"></p><font face="Arial, Helvetica, sans-serif" size="2">Your announcement has been successfully uploaded. Thank you!</font></p>";
}
}For some reason, the script is compleyely ignoring my if{} statement, and no matter what I do, either try to type in text in the text field or try to upload a file, the script always ends up du ping the error text: "There was an error uploading your file! <br>Please make sure you are only uploading only pdf files! Other file types will be rejected." I've used pretty much this same script on other wesbites, but haven't had this many problems. I only want user to be able to upload >pdf files, nothing else, hence the if(!in_array(...) statement. If the file extension is not ".pdf" or ".PDF", then the file gets rejected and nothing happens.
I was hoping someone could help me here, maybe suggest a better way of doing this or pointing me in the proper direction as to where I may find a better example to edit to my own needs.
thanks