Don't like ads? PRO users don't see any ads ;-)
Guest

upload

By: a guest on Jun 21st, 2012  |  syntax: PHP  |  size: 0.87 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?
  2.  
  3.    if ( isset ($_POST['action']) ) {
  4.  
  5.       if($_POST['action'] == "Upload Image") {
  6.  
  7.          unset($imagename);
  8.  
  9.  
  10.  
  11.          if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES;
  12.  
  13.  
  14.  
  15.          if(!isset($_FILES['fileUpload'])) $error["image_file"] = "An image was not found.";
  16.  
  17.  
  18.  
  19.          $imagename = basename($_FILES['fileUpload']['name']);
  20.  
  21.  
  22.  
  23.          if(empty($imagename)) $error["imagename"] = "The name of the image was not found.";
  24.  
  25.  
  26.  
  27.          if(empty($error)) {
  28.  
  29.             $newimage = "images/" . $imagename;
  30.  
  31.             //echo $newimage;
  32.  
  33.             $result = @move_uploaded_file($_FILES['fileUpload']['tmp_name'], $newimage);
  34.  
  35.             if ( empty($result) ) $error["result"] = "There was an error moving the uploaded file.";
  36.  
  37.          }
  38.  
  39.       }
  40.  
  41.    } else {
  42.  
  43.       echo "no form data found";
  44.  
  45.    }
  46.  
  47. ?>