最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

OpenBrowse Dialog box in phpjavascript? - Stack Overflow

programmeradmin12浏览0评论

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

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

Share Improve this question edited Dec 28, 2012 at 16:44 Dhwani asked Dec 28, 2012 at 14:38 DhwaniDhwani 7,62618 gold badges81 silver badges143 bronze badges 5
  • With modern day browsers, you are not going to get the file path. – epascarello Commented Dec 28, 2012 at 14:50
  • @Dhwani - you can not get the path of file, like, suppose your file is in c:\dhwani\filename.jpg, you will not get this path anyway. – Pankit Kapadia Commented Dec 28, 2012 at 15:29
  • @PankitKapadia , Hey Then How I am supposed to add image path in my database? I want that when user select from browse dialog, I get that file's path and store that database, so it reduce my database size. – Dhwani Commented Dec 28, 2012 at 16:25
  • @Dhwani - you can store images making directories of userids, so that you will not need storing path in database as you can show images with the same. Its easy, dont make it complicated. – Pankit Kapadia Commented Dec 29, 2012 at 17:00
  • @PankitKapadia, I have done it successfully, thanks. – Dhwani Commented Dec 29, 2012 at 17:23
Add a comment  | 

4 Answers 4

Reset to default 4

You can use file uploading forms with html and send the form to your PHP file to handle the file contents. 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:

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

You can put a form element by using <input type="file">

If you only want the path without uploading the file. You can use 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.

Check the Javascript File Api examples here if you want more .. 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....

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

发布评论

评论列表(0)

  1. 暂无评论