Problem with $HTTP_POST_FILES

Discussion in 'PHP' started by Bekah, Feb 16, 2007.

  1. #1
    Someone please help: I have 2 files. One browses SelectFile.php and AddNews.php. The first file helps to upload the file, the second captures the value and outputs the file name in the text area "NewsTitle" => $fname holds the value of $HTTP_POST_FILES['userfile']['name']; but when I try to out this value, does not print it out!!! It looks like the parameter passing from SelectFile.php to AddNews.php is not working. Someone - HELP! - JoseA

    ****************************************************

    SelectFile.php




    <?
    include("../classes/conn.php");
    $conn = New conn;
    $conn->connect();
    //include("../classes/credentials.php");
    //$chkrights = new verifier;
    //$chkrights->loadrights($EID);

    ?>
    <html>
    <head>
    <title>Insert News Item</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="../clients.css" type="text/css">

    <script language = 'Javascript'>
    function validateform()
    {
    if(document.frmUpload.userfile.value == "")
    {
    alert("Please choose a file before clicking to send send");
    return false;
    }
    }

    </script>

    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <form enctype="multipart/form-data" action="addnews.php" " method="post" name = "frmUpload" onsubmit ="return validateform();">

    <table width="95%" border="0" cellspacing="2" cellpadding="0" align="center" bgcolor="teal">
    <tr>
    <td>
    <div align="center"><b><font color="#ffffff"> Step 1: Upload Your Document</font></b></div>
    </td>
    </tr>
    <tr>
    <td height="5">
    <table align="center" width="100%" bgcolor="#FFFFFF" cellspacing="1" border="0" cellpadding="0" class="text">
    <tr>
    <td nowrap align="right" valign="top" class="text2">
    <div align="left"></div>
    </td>
    <td valign="baseline">
    <input name="userfile" type="file" class="text2">
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right" class="text2">
    <div align="left"></div>
    </td>
    <td>
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right" class="text2">
    <div align="left"></div>
    </td>
    <td>
    <input type=hidden name="upload" value="upload">
    <input type="submit" value="Send File" name="submit2" class="text2">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <p>&nbsp; </p>
    </form>
    </body>
    </html>

    ********************************************************

    AddNews.php

    <?
    include("../classes/error.php");
    include("../classes/conn.php");
    include("../classes/select.php");
    include ("classes/news.php");
    include("../classes/cleaninput.php");
    $conn = New conn;
    $conn->connect();
    //$se = new select;
    $news = new news;

    if (isset($upload))
    {
    //$fname = $HTTP_POST_FILES['userfile']['name'];
    $fname = $_FILES['userfile']['name'];
    $tname = $HTTP_POST_FILES['userfile']['tmp_name'];
    $news->set_path($fname);
    $news->move_file('userfile',$fname,$tname);
    }

    if (isset($add))
    {
    //Removing Illegal Characters
    $NewsTitle=RemoveillegalCharacters($NewsTitle);
    $NewsCaption=RemoveillegalCharacters($NewsCaption);

    $news->set_date();
    $news->add_news($NewsTitle,$NewsCaption,$NewsFileName,$ExpDate);
    $ID=mysql_insert_id();
    // $se->audit_trail("New","New News Item $NewsCaption ",$EID,"News",$ID);
    $url="viewnewslist.php";
    echo("<script language=JavaScript>window.document.location='".$url."'</script>");
    }
    ?>
    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
    <title>Add News Item Details</title>
    <link rel="stylesheet" href="../css/clients.css" type="text/css">
    <link rel="stylesheet" href="../css/calendar.css" type="text/css">
    <script language="JavaScript" src="../scripts/calendarcode2.js">
    </script>
    </head>
    <body bgcolor="#FFFFFF" leftmargin="2" topmargin="2" text="#000000" link="#0000FF"><DIV class=text id=popupcalendar></DIV>
    <form method="post" action="<?$PHP_SELF?>" name="form1">
    <table width="95%" border="0" cellspacing="2" cellpadding="0" align="center" bgcolor="teal">
    <tr>
    <td>
    <div align="center"><b><span class="textBig2"> Step 2 - Insert Title and
    Caption </span></b></div>
    </td>
    </tr>
    <tr>
    <td height="5">
    <table align="center" width="100%" bgcolor="#FFFFFF" cellpadding="0" cellspacing="2" border="0">
    <tr valign="baseline">
    <td nowrap align="right" class="text2" valign="top">
    <div align="left">Title:</div>
    </td>
    <td>
    <textarea name="NewsTitle" cols="32" rows="3" class="text"><?echo $fname?></textarea>
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right" class="text2" valign="top">
    <div align="left">Caption:</div>
    </td>
    <td>
    <textarea name="NewsCaption" cols="32" rows="8" class="text"></textarea>
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right" class="text2" valign="top">
    <div align="left">Expiry Date:</div>
    </td>
    <td valign="top">
    <input type="text" name="ExpDate" value="" size="10" class="text" readonly><a class="so-BtnLink" href="javascript:calClick();return false;"
    onmouseover="calSwapImg('BTN_date1', 'img_Date_OVER',true); "
    onmouseout="calSwapImg('BTN_date1', 'img_Date_UP',true); "
    onclick="calSwapImg('BTN_date1', 'img_Date_DOWN');
    showCalendar('form1','ExpDate','BTN_date1');return false;"><img align="absmiddle" border="0" name="BTN_date1" src="../calendar/btn_date_up.gif" width="22" height="17" alt="From Date"></a>
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right" class="text2" valign="top">
    <div align="left"></div>
    </td>
    <td>
    <input type="text" name="NewsFileName" value="<?echo $fname?>">
    <input type="hidden" name="add" value="add">
    </td>

    </tr>
    <tr valign="baseline">
    <td nowrap align="right" class="text2" valign="top">
    <div align="left"></div>
    </td>
    <td>
    <input type="submit" value="Save" name="submit" class="text2">
    <input type="reset" name="Reset" value="Reset" class="text2">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <input type="hidden" name="MM_insert" value="true">
    </form>
    </body>
    </html><?
    $conn->discon();?>
     
    Bekah, Feb 16, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try $_FILES instead.
     
    nico_swd, Feb 16, 2007 IP