Hi,

I was reviewing an example for uploading a file via PHP but the
example seems to negate a real example with a real database over the
internet. In other words the script in the book seems oriented towards
localhost but doesn't show any examples of creating an actual table in
MySQL. Does anyone know how to adapt the code?

Here's the sample code of the two supporting files:

/* FILE NUMBER ONE */

<?php
 /* Script name: uploadFile.php
  * Description: Uploads a file via HTTP with a POST form. 
  */
  if(!isset($_POST['Upload']))                         #5
  {
    include("form_upload.inc");
  }
  else                                                 #9
  {
    if($_FILES['pix']['tmp_name'] == "none")          #11
    {
      echo "<p style='font-weight: bold'>
                File did not successfully upload. Check the 
            file size. File must be less than 500K.</p>";
      include("form_upload.inc");
      exit();
    }
    if(!ereg("image",$_FILES['pix']['type']))         #19
    {
      echo "<p style='font-weight: bold'>
                File is not a picture. Please try another 
            file.</p>";
      include("form_upload.inc");
      exit();
    }
    else                                              #27
    {
      $destination='c:\data'."\\".$_FILES['pix']['name'];
      $temp_file = $_FILES['pix']['tmp_name'];
      move_uploaded_file($temp_file,$destination);
      echo "<p style='font-weight: bold'>
                The file has successfully uploaded:
            {$_FILES['pix']['name']} 
            ({$_FILES['pix']['size']})</p>"; 
    }
  }
?>


/* FILE NUMBER TWO */

<!-- Program Name: form_upload.inc
     Description:  Displays a form to upload a file -->
<html>
<head><title>File Upload</title></head>
<body>
<ol><li>Enter the file name of the product picture you 
        want to upload or use the browse button 
        to navigate to the picture file.</li>
    <li>When the path to the picture file shows in the
        text field, click the Upload Picture button.</li>
</ol> 
<div align="center"><hr />
<form enctype="multipart/form-data" 
        action="uploadFile.php" method="POST">
  <input type="hidden" name="MAX_FILE_SIZE" 
         value="500000">
  <input type="file" name="pix" size="60">
  <p><input type="submit" name="Upload" 
        value="Upload Picture">
</form>
</div></body></html>





Thanks,

Floyd



Reply via email to