I modified an image uploading script I use on a few sites to upload excel and other documents, but for some reason I can't figure out to save my life, the fileName variable is not getting passed through when the form is submitted, so the copy function is failing. I've run out of things to test with no progress made.
Here's the source code:
PHP Code:
<table width="100%" cellpadding="0" cellspacing="5" border="0">
<tr>
<td class="boxTitle">ADD PROGRAM / RESOURCE</td>
</tr>
<tr>
<td class="boxContent">
<?
$action = $_POST['action'];
if($action!="submitted"){
?>
<form method="post" action="<? print($PHP_SELF); ?>" ENCTYPE="multipart/form-data" name="uploadProgram">
<input type="hidden" name="action" value="submitted">
<table cellpadding="5" cellspacing="0" border="0">
<tr>
<td><strong>Type</strong></td>
<td>
<select class="normal" name="type">
<option value="Document">Document (Excel, etc.)</option>
<option value="OtherSite">Other Website</option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong>Other Site URI</strong></td>
<td>http://<input type="text" class="normal" size="63" name="URI"></td>
</tr>
<tr>
<td valign="top"><strong>Document File</strong></td>
<td><input type="file" class="normal" size="50" name="fileName"></td>
</tr>
<tr>
<td><strong>Title</strong></td>
<td><input type="text" size="70" class="normal" name="title"></td>
</tr>
<tr>
<td valign="top"><strong>Description</strong><br></td>
<td><textarea cols="80" rows="4" class="normal" name="description"></textarea></td>
</tr>
<tr><td colspan="2"><input type="submit" value=" add program " class="normalButton"></td></tr>
</table>
</form>
<?
}
else{
$type = $_POST['type'];
$title = $_POST['title'];
$fileName = $_POST['fileName'];
$description = $_POST['description'];
$URI = $_POST['URI'];
if($type=="OtherSite"){
$fileName = $URI;
mysql_query("INSERT INTO programs VALUES (
'',
'$title',
'$description',
'$type',
'$fileName'
)");
print('Program successfully added. <a href="index.php">Add Another »</a>');
}
elseif($type=="Document"){
if(empty($fileName)){
print 'filename empty';
}
$uploadPath = "../../programs/";
// MAKE NEW FILE NAME
$fileNameForm = str_replace(" ", "", $fileName);
// NO FILE SELECTED
if(!isset($HTTP_POST_FILES['fileName'])){
echo "Select a document file to upload";
}
// CHECK IF IS UPLOADED FILE
if(is_uploaded_file($HTTP_POST_FILES['fileName']['tmp_name'])){
// FILE ALREADY EXISTS
if(file_exists($uploadPath . $HTTP_POST_FILES['fileName']['name'])){
echo "A file with that name already exists<br>\n";
}
// COPY FILE TO DIRECTORY
$res = copy($HTTP_POST_FILES['fileName']['tmp_name'], $uploadPath . $fileNameForm);
if(!res){
echo 'File Upload Failed! Please go back and try again.';
}
else{
// INSERT INTO DB, PRINT SUCCESS
mysql_query("INSERT INTO programs VALUES (
'',
'$title',
'$description',
'$type',
'$fileNameForm'
)");
print('Program successfully added. <a href="index.php">Add Another »</a>');
print('filename ' . $fileName . ', ' . $fileNameForm);
}
}
}
}
?>
</td>
</tr>
<tr>
<td class="boxTitle">PROGRAMS / RESOURCES ON RECORD</td>
</tr>
<tr>
<td class="boxContent">
<table width="100%" cellpadding="5" cellspacing="1" border="0">
<tr>
<td bgcolor="#e5e5e5"><strong>Program / Resource</strong></td>
<td colspan="2" bgcolor="#e5e5e5" align="center"><img src="../../images/icons/checkmark.gif"><br></td>
</tr>
<?
$resList = mysql_query("SELECT * FROM programs ORDER BY title ASC");
$numList = mysql_numrows($resList);
for($iList = 0; $iList < $numList; $iList++){
$programID = mysql_result($resList,$iList,"programID");
$title = mysql_result($resList,$iList,"title");
$fileName = mysql_result($resList,$iList,"fileName");
$type = mysql_result($resList,$iList,"type");
?>
<tr>
<td bgcolor="#ffffff">
<?
if($type=="OtherSite"){
print('<a target="_blank" href="http://' . $fileName . '"><strong>' . $title . '</strong></a><br>');
}
elseif($type=="WebPage"){
print('<a target="_blank" href="/programs.php?show=program&programID=' . $programID . '"><strong>' . $title . '</strong></a><br>');
}
elseif($type=="Document"){
print('<a target="_blank" href="/programs/' . $fileName . '"><strong>' . $title . '</strong></a><br>');
}
?>
</td>
<td bgcolor="#eeeeee" align="center">
<form method="post" action="edit_program.php"><input type="hidden" name="programID" value="<? print($programID); ?>">
<input type="image" src="/images/icons/button_edit.gif">
</form>
</td>
<td bgcolor="#eeeeee" align="center">
<form method="post" action="delete_program.php"><input type="hidden" name="programID" value="<? print($programID); ?>">
<input type="image" src="/images/icons/button_delete.gif" onclick="javascript:return confirm('Are you sure you want to delete this program?')">
</form>
</td>
</tr>
<?
}
?>
</table>
</td>
</tr>
</table>
Anyone have any ideas? Thanks.
|