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.

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

报告相同问题?