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 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题