cannot upload a file in javascript using php -


i trying upload file using php. following error generated. error: problem occurred during file upload! . using ubuntu os. think error generated while trying save file. used following code

<html> <body>   <form enctype="multipart/form-data" action="upload.php" method="post">     <input type="hidden" name="max_file_size" value="1000000" />     choose file upload: <input name="uploaded_file" type="file" />     <input type="submit" value="upload" />   </form> </body> </html>   <?php //Сheck have file if((!empty($_files["uploaded_file"])) && ($_files['uploaded_file']['error'] == 0)) {   //check if file jpeg image , it's size less 350kb   $filename = basename($_files['uploaded_file']['name']);   $ext = substr($filename, strrpos($filename, '.') + 1);   if (($ext == "jpg") && ($_files["uploaded_file"]["type"] == "image/jpeg") &&      ($_files["uploaded_file"]["size"] < 350000)) {     //determine path want save file       $newname = dirname(__file__).'/upload/'.$filename;       //check if file same name exists on server       if (!file_exists($newname)) {         //attempt move uploaded file it's new place         if ((move_uploaded_file($_files['uploaded_file']['tmp_name'],$newname))) {            echo "it's done! file has been saved as: ".$newname;         } else {            echo "error: problem occurred during file upload!";         }       } else {          echo "error: file ".$_files["uploaded_file"]["name"]." exists";       }   } else {      echo "error: .jpg images under 350kb accepted upload";   } } else {  echo "error: no file uploaded"; } ?> 

what problem of code? or because of file permision access folder?

find error occurs.

<?php  $msg = ''; $upload_key = 'uploaded_file';  if (isset($_files[$upload_key])) {      try {          $error = $_files[$upload_key]['error'];         switch ($error) {             case upload_err_ini_size:                 throw new exception('exceeded upload_max_filesize');             case upload_err_form_size:                 throw new exception('exceeded max_file_size');             case upload_err_partial:                 throw new exception('incomplete file uploaded');             case upload_err_no_file:                 throw new exception('no file uploaded');             case upload_err_no_tmp_dir:                 throw new exception('no tmp directory');             case upload_err_cant_write:                 throw new exception('can\'t write data');             case upload_err_extension:                 throw new exception('extension error');         }          $finfo    = new finfo(fileinfo_mime);         $name     = $_files[$upload_key]['name'];         $tmp_name = $_files[$upload_key]['tmp_name'];         $size     = $_files[$upload_key]['size'];          if ($size > 350000)             throw new exception('exceeded 350kb limit');         if (!is_uploaded_file($tmp_name))             throw new exception('not uploaded file');          $type = $finfo->file($tmp_name);          if ($type === false)             throw new exception('failed mimetype');         if ($type !== 'image/jpeg; charset=binary')             throw new exception('only jpeg files available');          $new_name = dirname(__file__).'/upload/'.$name;          if (is_file($new_name))             throw new exception("the file {$new_name} exists");          if (!move_uploaded_file($tmp_name,$new_name))             throw new exception('failed move uploaded file');          $msg = "file uploaded {$new_name}";      } catch (exception $e) {          $msg = 'error: '.$e->getmessage();      }  } ?> <!doctype html> <html> <head> <title>uploader</title> </head> <body> <form enctype="multipart/form-data" action="<?php echo $_server['script_name']; ?>" method="post"> <div><input type="hidden" name="max_file_size" value="1000000" /></div> <div>choose file upload: <input name="uploaded_file" type="file" /></div> <div><input type="submit" value="upload" /></div> </form> <p> <?php echo $msg.php_eol; ?> </p> </body> </html> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -