Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Passing variable to function from form.

$
0
0

Hi Guys,

 

I am struggling to pass form input data to function (store to blob).

 

FORM:

    <form action="admin.php?action=<?php echo $results['formAction']?>" method="post" enctype="multipart/form-data">

   <input type="file" name="file" size="40" id="file" required autofocus maxlength="255" />
        <input type="hidden" name="MAX_FILE_SIZE" value="50000000">

FUNCTION:

 public function uploadImage() {
  if ( !is_null( $this->img_id ) ) trigger_error ( "cmsImagesClass::uploadImage(): Attempt to insert an object that already has its ID property set (to $this->img_id).", E_USER_ERROR );
  // Prepare image
  $imageFile = file_get_contents($_FILES['file']['tmp_name']);
  // Insert link
  $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  $sql = "INSERT INTO images ( img_name, img_blob) VALUES ( :img_name, :imageFile)";
    $st = $conn->prepare ( $sql );
    $st->bindValue( ":img_name", $this->img_name, PDO::PARAM_STR );
    $st->bindValue( ":imageFile", $this->img_blob, PDO::PARAM_LOB);

What I am doing wrong? As image not being stored. If I am commenting out imageFile and storing img_name - when is fine, I can see that record was added, but storing file - not giving any errors


Viewing all articles
Browse latest Browse all 13200

Trending Articles