doufeixi6014 2012-10-09 12:09
浏览 24
已采纳

如何在获取变量的当前时间和日期后设置jpeg扩展名?

I am uploading an image to a folder name "upload". Then I am changing the name and extension of the image. I am getting the current time and date with default time zone now I am trying to set the image extension to "jpeg" after the getted date and time I was tried but is not given result I put my code here

I suppose when I upload image at that time my file name is "NEWYORK.JPG" But after upload the image I want to change the file name is "9/10/2012/05:31:15.jpeg" from get the current time and date set default time zone.

date_default_timezone_set('Asia/Kolkata');
$imagename = date('d/m/Y-h:i:s', time());
$imagename=basename($imagename,".jpg");
echo $filename = $imagename;
$upload   = $_FILES['ctgimage'];
$target_path = "upload/";

 echo $target_path .= $filename . "." . path_info($upload["name"], PATHINFO_EXTENSION);
  if(move_uploaded_file($upload["tmp_name"],$target_path))
  {
          echo "uploaded successfully";           $cname=$_POST['ctgname'];
          mysql_query("insert into category(ctg_name,ctgimage) 
               values('$cname','$target_path')");

  }
  • 写回答

4条回答 默认 最新

  • duanqing3026 2012-10-09 12:13
    关注

    Some Errors

    • It should be pathinfo not path_info
    • Use a valid File name like d-m-Y for folder h.i.s for file
    • Too many Duplication
    • Avoid SQL Injection by escaping

    Example :

    date_default_timezone_set('Asia/Kolkata');
    
    $target_path = "upload/";
    $imageDir = date('d-m-Y', time());
    $imageName = date('h.i.s', time());
    
    $upload = $_FILES['ctgimage'];
    $uploadExtention = pathinfo($upload["name"], PATHINFO_EXTENSION);
    
    if (! is_dir($target_path . "/" . $imageDir)) {
        mkdir($target_path . "/" . $imageDir);
    }
    
    $target_path = "$target_path/$imageDir/$imageName.$uploadExtention";
    $cname = mysql_real_escape_string($_POST['ctgname']);
    
    if (move_uploaded_file($upload["tmp_name"], $target_path)) {
        echo "uploaded successfully";
    
        mysql_query("insert into category(ctg_name,ctgimage)
        values('$cname','$target_path')");
    }
    

    PHP DOC on mysql_*****

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看