uploading files and putting path into db
Posted: Fri Dec 13, 2002 3:29 pm
I am having some serious trouble with this upload script. I am trying to make it so that I can upload a .pdf newsletter and have it be uploaded to the server as well as put in a mysql database. Here is my code, beware:
the upload.php file resides in the /newsletter/admin directory and the directory I want stuff uploaded to is /newsletter/downloads. I've never really written an upload script before so if you could help I'd appreciate it a bunch! Thanks
here are the errors I get:
Code: Select all
<?php
if (!IsSet($action)) {
?>
<form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="fileUpload">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Newsletter
Title:</font></td>
<td width="75%"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">File
Attachment (.pdf):</font></td>
<td><input type="file" name="pdfnewsletters"></td>
</tr>
<tr>
<td> </td>
<td> <input type="hidden" name="username"value="<?php echo("$username"); ?>">
<input name="action" type="submit" id="action" value="Submit">
<input name="Reset" type="reset" id="Reset" value="Reset"></td>
</tr>
</table>
</form>
<?php
}
else {
copy($_FILES['pdfnewsletters']['tmp_name'], "../downloads/".$_FILES['pdfnewsletters']['name']) or die("could not copy");
echo "";
echo "Name: ".$_FILES['pdfnewsletters']['name']."";
echo "Size: ".$_FILES['pdfnewsletters']['size']."";
echo "Type: ".$_FILES['pdfnewsletters']['type']."";
$path = "http://www.pancorp.com/newsletter/downloads/".$_FILES['pdfnewsletters']['name']";
mysql_connect($hostname, $user, $pass);
mysql_select_db("pancorp");
$sql = "INSERT INTO newsletters SET
name = '$name',
link = '$path',
username = '$username'";
$result = mysql_query($sql) or die(mysql_error());
}
?>here are the errors I get:
Warning: Undefined variable: _FILES in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 55
Warning: Undefined variable: _FILES in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 55
Warning: Unable to open '' for reading: No such file or directory in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 55
could not copy