Image upload not moving file php mysql -


i'm trying build image upload on site. code i'm using inserts value database, image isn't moved directory?

can me on this, or give me advice on how debug this?

inputs

 <label for="picture_1">picture 1 : </label>     <input type="file" name="picture_1" id="picture_1" /> </li> <li>     <label for="picture_2">picture 2 : </label>     <input type="file" name="picture_2" id="picture_2" /> </li> <li>     <label for="picture_3">picture 3 : </label>     <input type="file" name="picture_3" id="picture_3" /> 

file upload

if(sizeof($_files)){  for($i = 1; $i <= 3; $i++) {  $afile = $_files['picture_'.$i];  if(empty($afile['tmp_name'])) continue; # skip empty elements      $allowedexts = array("jpg", "jpeg", "gif", "png");     $extension = end(explode(".", $afile["name"]));     if ((($afile["type"] == "image/gif")     || ($afile["type"] == "image/jpeg")     || ($afile["type"] == "image/png")     || ($afile["type"] == "image/pjpeg"))     && ($afile["size"] < 200000000)     && in_array(strtolower($extension), $allowedexts))       {       if ($afile["error"] > 0)         {         echo "return code: " .$afile["error"] . "<br>";         }       else         {                if (file_exists("upload/" . $afile["name"]))           {           echo $afile["name"] . " exists. ";           }         else           {           move_uploaded_file($afile['tmp_name'],              "upload/" .$afile["name"]);            echo "image uploaded successfully";           }         }       }     else     {       echo "invalid file";       } } 

complete page

include 'assets/connection.class.php';   $firstname = $_post['first_name'];   // connection data (server_address, database, name, poassword) $hostdb = 'localhost'; $namedb = ''; $userdb = ''; $passdb = '';  try {   // connect , create pdo object  $conn = new pdo("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); $conn->exec("set character set utf8");      // sets encoding utf-8 $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);   $sql = "insert stmt here";   $statement = $conn->prepare($sql);  $statement->bindvalue(":firstname", $firstname);  ...  list of bind values etc here    $count = $statement->execute();    $conn = null;        // disconnect } catch(pdoexception $e) {   echo $e->getmessage(); }   if(sizeof($_files)){      for($i = 1; $i <= 3; $i++) {      $afile = $_files['picture_'.$i];      if(empty($afile['tmp_name'])) continue; # skip empty elements          $allowedexts = array("jpg", "jpeg", "gif", "png");         $extension = end(explode(".", $afile["name"]));         if ((($afile["type"] == "image/gif")         || ($afile["type"] == "image/jpeg")         || ($afile["type"] == "image/png")         || ($afile["type"] == "image/pjpeg"))         && ($afile["size"] < 200000000)         && in_array(strtolower($extension), $allowedexts))           {           if ($afile["error"] > 0)             {             echo "return code: " .$afile["error"] . "<br>";             }           else             {                    if (file_exists("upload/" . $afile["name"]))               {               echo $afile["name"] . " exists. ";               }             else               {               move_uploaded_file($afile['tmp_name'], "'upload/" .$afile["name"]."'");                echo "image uploaded successfully";               }                      }           }         else         {           echo "invalid file";           }     }  }   // if data added ($count not false) displays number of rows added if($count !== false) echo 'number of rows added: '. $count;    ?>   <a href="test.php">go </a> 

error log

[tue aug 13 19:27:31 2013] [error] [client 89.240.60.62] php warning:  move_uploaded_file('upload/13-001945_1.jpg'): failed open stream: no such file or directory in /home/liam.co.uk/domains/tiercakes.co.uk/public_html/access/add-cake.php on line 132, referer: http://www.tiercakes.co.uk/access/add-cake.php  [tue aug 13 19:27:31 2013] [error] [client 89.240.60.62] php warning:  move_uploaded_file(): unable move '/tmp/phpxrwtlm' ''upload/13-001945_1.jpg'' in /home/liam.co.uk/domains/tiercakes.co.uk/public_html/access/add-cake.php on line 132, referer: http://www.tiercakes.co.uk/access/add-cake.php 

you missing closing curly brace creating error in php file , therefore not execute. should end of code this:

    else         {           echo "invalid file";           }     } } 

just add last curly brace looks like, , should good.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -