dqzuo0327 2013-03-26 07:03
浏览 8

PHP图像上传文件名

Okay, so short and sweet; I already have an image uploader working perfectly in PHP, from a HTML form. I now need to somehow store an uploaded images name to a variable in Javascript. The image name must be saved without the image path. For example: images123.jpg.

I am creating a kind of sign up form, so I don't need to save every image as a variable, just the current one, so it is saved on the users account as a variable.

Honestly, I'm completely new to PHP, and I'm still learning, so I have no clue on how to do this.

All help would be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • doubi9531 2013-03-26 07:16
    关注

    this is work for you use your php code here

    <?php
    if ($_FILES["file"]["error"] > 0)
    {
      echo "Error: " . $_FILES["file"]["error"] . "<br>";
    }
    else
    {
     $imageName = $_FILES["file"]["name"];
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
    ?>
      <input type="hidden" id="imgName" value="<?php echo $imageName; ?>" />
    

    Get image name in javascript by hidden field name

      var imgName = document.getElementById("imgName").value;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单