duanhoupeng6642 2014-06-11 16:32
浏览 6
已采纳

没有使用PHP上传的文件名称扩展

I want to add this option for my users. They will be presented with a "Browse" button, they can MULTI select different files. And once they are done selecting the files.I want to collect the file names alone without any upload and pass it onto my form action webpage. process.php

Basically, my program will work on the file names.

I've browsed several posts such as this How to Get File Name from Upload Form Using jQuery?. But wasn't able to put together my knowledge on jquery and php together. Also, creating a multi file upload.

MY ATTEMPT

<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html> 

upload_file.php

<?php
if ($_FILES["file"]["error"] > 0) {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
  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"];
}
?> 

But this gives file name only AFTER upload is done. I do not know any other method.

Thank you for your answer.

Best Regards, John

  • 写回答

1条回答 默认 最新

  • dronthpi05943 2014-06-11 17:30
    关注

    Try this way: http://jsfiddle.net/p42Wv/

    The global idea is, when you select a file, the file name is extracted at the same time and put in another input (in that example, the #filename one).

    In your PHP code, you can get the file name by using the $_POST verb as usual.

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题