php - change name on upload -


i’m updating admin side of website.

i have managed include add page uploads database site display content.

within page image upload button.

when select file upload button saves image /images folder.

however. when upload images using feature on ipad, uploads images image.jpg.

what need this:

i need uploaded images save name of brand , not original uploaded image name. if upload "image.jpg", enter apple brand, want image save apple.jpg upload file.

my current add.php page this:

<?php  session_start();  include_once('../include/connection.php');  if (isset($_session['logged_in'])){   if (isset($_post['title'], $_post['content'])) {         $title   = $_post['title'];         $content = nl2br($_post['content']);         if (!empty($_post['image']))         {             $image = $_post['image'];         }         else         {             $image = $_post['imageupload'];              if (isset($_files['imageupload']))             {               $errors = array();               $allowed_ext = array('jpg', 'jpeg', 'png', 'gif');                $file_name = $_files['imageupload'] ['name'];               $file_ext = strtolower (end (explode ('.', $file_name)));               $file_size = $_files['imageupload'] ['size'];               $file_tmp = $_files['imageupload'] ['tmp_name'];                if (in_array ($file_ext, $allowed_ext) === false) {                      $errors[] = 'file extension not allowed';               }                if ($file_size > 2097152) {                      $errors[] = 'file size must under 2mb';               }                if (empty($errors)) {                      if (move_uploaded_file($file_tmp, 'images/'.$file_name)) {                            echo 'file uploaded';                            $image = 'http://www.xclo.mobi/xclo2/admin/images/'.$file_name;               }               }else{                     foreach ($errors $error)                     echo $error, '<br />';               }              }         }         $link     = $_post['link'];         $category = $_post['category'];         $brand    = $_post['brand'];   if (empty($title) or empty($content)) {          $error = 'all fields required!'; }else{  $query = $pdo->prepare('insert mobi (promo_title, promo_content, promo_image, promo_link, promo_cat, promo_name) values(?, ?, ?, ?, ?, ?)');  $query->bindvalue(1, $title);  $query->bindvalue(2, $content);  $query->bindvalue(3, $image);  $query->bindvalue(4, $link);  $query->bindvalue(5, $category);  $query->bindvalue(6, $brand);         $query->execute();     header('location: index.php'); }  }           ?>     <?php  if (isset($_files['filedata'])) { // , if ok     if ($_files['filedata']['error'] !== upload_err_ok)     exit('upload failed. error code: ' . $_files['image']['error']);      $filename = $_files['filedata']['name'];     $targetpath    = "../img/news/" . $filename; //target directory relative script location      $copy = copy($_files['filedata']['tmp_name'], $targetpath); } ?>  <html> <head> <title>add article</title> <link rel="stylesheet" href="../other.css" /> </head>  <body> <div class="container"> <a href="index.php" id="logo"><b>&larr; back</b></a>  <br />  <div align="center"> <h4>add article</h4>  <?php if (isset($error)) { ?>      <small style="color:#aa0000;"><?php echo $error; ?></small><br /><br /> <?php } ?>  <form action="" method="post" autocomplete="off" enctype="multipart/form-data">  <input type="text" name="title" placeholder="title" /><br /><br /> <textarea rows="15" cols="50" placeholder="content" name="content"></textarea><br /><br /> <input name="imageupload" type="file" id="image" placeholder="imageupload" /> <input type="text" name="image" placeholder="image" /><br /><br /> <input type="link" name="link" placeholder="link" /><br /><br /> <input type="category" name="category" placeholder="category" /><br /><br /> <input type="category" name="brand" placeholder="brand" /><br /><br /> <input type="submit" value="add article" />  </form> </div> </div> </body> </html>   <?php }else{        header('location: index.php'); }  ?> 

please can help? thank you.

1) image extension

$ext = pathinfo($filename, pathinfo_extension);

2) upload file concatenatin brand name & extension

move_uploaded_file($_files['imageupload'] ['tmp_name'], $_post['your_brand'].'.'.$ext);


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -