Http Header question

William Prothero prothero at earthednet.org
Tue Jan 19 17:44:41 EST 2016


Folks:
I’m setting up a php sendmail script using phpSendmail and I’m trying to get the file upload for attachments part working. The examples I find are in html and the “type" is listed as “file”.

Basically, I’m trying to reproduce this, in a “post” command:

<html>
   <body>
      
      <form action = "" method = "POST" enctype = "multipart/form-data">
         <input type = "file" name = "image" />
         <input type = "submit"/>
			
         <ul>
            <li>Sent file: <?php echo $_FILES['image']['name'];  ?>
            <li>File size: <?php echo $_FILES['image']['size'];  ?>
            <li>File type: <?php echo $_FILES['image']['type'] ?>
         </ul>
			
      </form>
      
   </body>
</html>
I figure it is probably a change in the http header, to get php to recognize the file as an upload, but I don’t know how to do this. Somehow, the php needs to get the filepath that I provide it, but ….. 

Any help would be very appreciated.
Best,
Bill

PS: The php in the example I’m trying to duplicate is:

<?php
   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size = $_FILES['image']['size'];
      $file_tmp = $_FILES['image']['tmp_name'];
      $file_type = $_FILES['image']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
      
      $expensions= array("jpeg","jpg","png");
      
      if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }
      
      if($file_size > 2097152) {
         $errors[]='File size must be excately 2 MB';
      }
      
      if(empty($errors)==true) {
         move_uploaded_file($file_tmp,"images/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
?>


William Prothero, Ph.D.
University of California, Santa Barbara, Emeritus
prothero at earthednet.org






More information about the Use-livecode mailing list