cusimar9
07-24-2007, 04:38 AM
I'm trying to get my head around someone else's code... and learn PHP at the same time.
I've got a simple file upload, but I can't see where its working out what the file name is.
// adds a news item to the database
if (!isset($submit))
{
echo "<form name='frmAdd' enctype='multipart/form-data' action='news_admin.php' method='post' onSubmit=\"return ValidateNews(document.frmAdd.title.value, document.frmAdd.news_text.value);\">";
echo "<table>";
echo "<tr><td><b><u>News Headline</u>:</b></td><td><input type='text' name='title' size='35'></td></tr>";
echo "<tr><td><b><u>News Text</u>:</b></td><td><textarea name='news_text' cols='35' rows='4'></textarea></td></tr>";
echo "<tr><td><b>Image File:</b></td><td><input type='file' name='imagefile'></td></tr>";
echo "</table>";
echo "<input type='hidden' name='mode' value='add'>";
echo "<input type='submit' name='submit' value='Add' title='Add News Item'>";
echo "</form>";
}
else
{
echo "THE FILE IS " . $imagefile_name;
}
The 'imagefile' and 'imagefile_name' names I've just made up, they're not mentioned anywhere else in the page. Yet the imagefile_name actually does hold the file name when the page is posted and a file uploaded. Is this a feature of PHP or is the code doing something I don't understand?
I've got a simple file upload, but I can't see where its working out what the file name is.
// adds a news item to the database
if (!isset($submit))
{
echo "<form name='frmAdd' enctype='multipart/form-data' action='news_admin.php' method='post' onSubmit=\"return ValidateNews(document.frmAdd.title.value, document.frmAdd.news_text.value);\">";
echo "<table>";
echo "<tr><td><b><u>News Headline</u>:</b></td><td><input type='text' name='title' size='35'></td></tr>";
echo "<tr><td><b><u>News Text</u>:</b></td><td><textarea name='news_text' cols='35' rows='4'></textarea></td></tr>";
echo "<tr><td><b>Image File:</b></td><td><input type='file' name='imagefile'></td></tr>";
echo "</table>";
echo "<input type='hidden' name='mode' value='add'>";
echo "<input type='submit' name='submit' value='Add' title='Add News Item'>";
echo "</form>";
}
else
{
echo "THE FILE IS " . $imagefile_name;
}
The 'imagefile' and 'imagefile_name' names I've just made up, they're not mentioned anywhere else in the page. Yet the imagefile_name actually does hold the file name when the page is posted and a file uploaded. Is this a feature of PHP or is the code doing something I don't understand?