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.)
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With