Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 224
Dhwani Avatar asked Dec 28 '12 14:12

Dhwani


3 Answers

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

like image 74
Stefan Dunn Avatar answered Oct 12 '22 09:10

Stefan Dunn


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/

like image 34
Sinan Avatar answered Oct 12 '22 08:10

Sinan


<input type="file">

no? or i'm something missing?

like image 36
Vladimir Gordienko Avatar answered Oct 12 '22 09:10

Vladimir Gordienko