Okay, so short and sweet; I already have an image uploader working perfectly in PHP, from a HTML form. I now need to somehow store an uploaded images name to a variable in Javascript. The image name must be saved without the image path. For example: images123.jpg.
I am creating a kind of sign up form, so I don't need to save every image as a variable, just the current one, so it is saved on the users account as a variable.
Honestly, I'm completely new to PHP, and I'm still learning, so I have no clue on how to do this.
All help would be greatly appreciated!
this is work for you use your php code here
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$imageName = $_FILES["file"]["name"];
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"];
}
?>
<input type="hidden" id="imgName" value="<?php echo $imageName; ?>" />
Get image name in javascript by hidden field name
var imgName = document.getElementById("imgName").value;
Using Jquery
$('#upload_document_name').bind('change', function() {
var logoName = $('#upload_document_name').val();
$('#uploadDocumentName').attr('value', logoName);
});
Note: There should be hidden or text field called "uploadDocumentName".