[thelist] OO PHP

Shashank Tripathi sub at shanx.com
Tue Feb 12 20:54:35 CST 2002


Hi Beau:

I wonder if I understand your problem correctly, but it could be as simply
resolved as passing the $HTTP_POST_FILES to your object's method and then
performing the relevant checking inside the method?

In any case, I don't know exactly which version of PHP but here is another
handy way of checking whether a file was uploaded (PS: I am including some
useful sample code below, just copy it to your server and test it out):

    Form tag:
    ----------
    <input type="file" name="my_image" value="Browse">


    PHP logic to check for posted info:
    ------------------------------
    if (isset($userfile) && !eregi("none", $userfile))
    {
        // P.S. isset() alone may not work
    }


So if your script draws the INPUT tag correctly, I am sure it names your
input tag as well. If this is so, you can use the same name to check for the
file being uploaded.

Meanwhile, here are two pages you should consider reading in detail, apart
from the working code sample below:

   o http://www.php.net/manual/en/features.file-upload.php
   o http://www.faqts.com/knowledge_base/view.phtml/aid/988/fid/62

Hope this helps!
</Shanx>

www.shanx.com



//---------------------------------------
// SAMPLE CODE BELOW: save as a php file and run
//---------------------------------------


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Binary file reading sample</title>
    <style>
        body, td, input, select { font-family: Arial; font-size: 9pt }
    </style>
</head>

<body bgcolor="#FFFFFF">
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo basename($PHP_SELF);
?>" METHOD="post">
  <table width="500" border="1" cellspacing="0" cellpadding="2"
align="center" bordercolor="#dfdfdf" bordercolordark="#ffffff">
  <tr bgcolor="#efefef" valign="middle" align="center">
      <td colspan="2" height="24"><b>TEST FOR UPLOADING A FILE</b></td>
  </tr>
  <tr>
    <td width="100" height="24">Select a file </td>
    <td>
      <input name="userfile" type="file">
      <input type="hidden" name="MAX_FILE_SIZE" value="1000000"><!-- VALUE
IN BYTES-->
    </td>
  </tr>
  <tr>
    <td width="100" height="24">&nbsp;</td>
    <td>
      <input type="submit" value="Send File" name="submit">
    </td>
  </tr>
</table>

  <br>
  <br>
</FORM>


<?php

set_time_limit(900);

if (isset($userfile) && !eregi("none", $userfile))
{

?>

    <table width="500" border="1" cellspacing="0" cellpadding="2"
align="center" bordercolor="#dfdfdf" bordercolordark="#ffffff">
      <tr bgcolor="#efefef" valign="middle" align="center">
        <td bgcolor="#efefef" height="24" valign="middle"><b>DETAILS OF THE
          UPLOADED FILE</b></td>
      </tr>
      <tr valign="middle" align="center">
        <td height="24" align="left">

        <b>You uploaded the file from your computer:</b> <br>
        <?php echo $userfile_name . "<br>Saved locally as: <font
color=#ff6600>$userfile</font>)"; ?><p>

        <b>The type of this file is:</b> <br>
        <?php echo $userfile_type; ?><p>

        <b>The size of this file is (in bytes):</b> <br>
        <?php echo $userfile_size; ?><p>

      </tr>
    </table>

<?php

}
else if ($REQUEST_METHOD == "POST")
{
?>

    <table width="500" border="1" cellspacing="0" cellpadding="2"
align="center" bordercolor="#dfdfdf" bordercolordark="#ffffff">
    <tr valign="middle" align="center">
    <td height="24" valign="middle">No file uploaded.<br>
    </td></tr></table>

<?
}
?>
</body>
</html>








More information about the thelist mailing list