简体   繁体   English

在php / javascript中打开/浏览对话框?

[英]Open/Browse Dialog box in php/javascript?

I am working on a PHP project, in which I need to store a path of an image when user select an image from open dialog box from a specified directory. 我正在开发一个PHP项目,当用户从指定目录的打开对话框中选择图像时,我需要存储图像的路径。 How can I do this? 我怎样才能做到这一点? I don't know how to open the Open/Browse dialog box and how to get that path in PHP/javascript. 我不知道如何打开打开/浏览对话框以及如何在PHP / javascript中获取该路径。 And I want that my other form data don't flush when I open the Open/Browse Dialog.(I want to put image file's path that user has selected in my database, so I can reduce my database size.) 当我打开打开/浏览对话框时,我希望我的其他表单数据不会刷新。(我想将用户在我的数据库中选择的图像文件的路径放在一起,这样我就可以减少我的数据库大小。)

You can use file uploading forms with html and send the form to your PHP file to handle the file contents. 您可以使用带有html的文件上载表单,并将表单发送到PHP文件以处理文件内容。 When a file is sent to the server it is stored in a temporary location. 将文件发送到服务器时,它将存储在临时位置。

W3Schools has a good tutorial on this, the HTML becomes: W3Schools有一个很好的教程,HTML变成:

<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>

and the PHP: 和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"];
  }
?>

http://www.w3schools.com/php/php_file_upload.asp http://www.w3schools.com/php/php_file_upload.asp

You can put a form element by using <input type="file"> 您可以使用<input type="file">放置表单元素

If you only want the path without uploading the file. 如果您只想要路径而不上传文件。 You can use javascript. 你可以使用javascript。

If you post the data to the server file's info will be available to PHP but also the file will be sent to server as well. 如果您将数据发布到服务器文件,那么PHP的信息将可用,但该文件也将被发送到服务器。

Check the Javascript File Api examples here if you want more .. http://www.html5rocks.com/en/tutorials/file/dndfiles/ 如果您想要更多, 查看此处的Javascript文件Api示例.. http://www.html5rocks.com/en/tutorials/file/dndfiles/

<input type="file">

no? 没有? or i'm something missing? 或者我缺少什么?

For dotNetAddict (if they are still interested) and any others similarly interested, try the following link for a good explanation of how to obtain the path to a file.... 对于dotNetAddict(如果他们仍然感兴趣)和任何其他同样感兴趣的人,请尝试以下链接以获得有关如何获取文件路径的详细说明....

http://www.w3schools.com/jsref/prop_fileupload_value.asp http://www.w3schools.com/jsref/prop_fileupload_value.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM