show image name through browse field in php - javascript

How can I show image name through the browse field. Sorry that, I am new in PHP.
I use this code, but it's not working
<input
id="photo"
type="file"
value="<?php echo $results['image'];?>"
class="form-control"
name="image" />

You can not show a image on a input field.
What you can do is:
<img src="allYourDomainURL/<?php echo $results['image'];?>" />
That would effectively show a real image to the user.

I'm guessing what you want to do is to show inside the input type file the image you uploaded once the form is submitted. I am afraid that is not possible.
What you can do is save the image on a folder inside your project, save that into a variable, for example $image. Then show it inside your form, you can even create a link so that when they click on it the image will appear on a different tab.

Related

To change the default text "No File Selected" of a browser button with some other text in JSP

I have a file browser button in my jsp. It has a text like "No File Selected" beside it at the very beginning. after selecting the file, it shows the file path instead of "No File Selected". Now I want to replace "No File Selected" with ".jpg" or the supported format names.
Is it possible to do so?
my code for the browser button..
<form:input name="file1" type="file" accept="image/png,image/jpeg"
id="files" path="" size="500" title="files" />
Use this style...
in order for you to make a design of you input file..
do not display the input.. just hide it and make a design on your button or whatever element you want. Just like my example below..
<input type="file" id="myUpload" style="display:none" />
<button type="button" onclick="javascript:document.getElementById('myUpload').click();">Upload Photo</button>
I hid the input while displaying the button and giving it an attribute onclick and letting the javascript do the magic..
here is the example:
http://jsfiddle.net/aYd72/
and better use bootstrap for better designs
I hope it will help you

Form input showing image insted of text value

I have a form which i am using to update adds on my site, I am filling input value with existing adds but there is a problem in form it is showing adds images instead of text value.
I need to update adds link by replacing the link value in input field.
Input field has value as
<input name="addtop" type="text" value="<a href="http://www.xxyy.com/4g...." target="_blank" <img src="http://www.xxyy.com/h4...."/></a>" />
when i try to load page it shows image in input field instead of text as:
<a href="http://www.xxyy.com/4g...." target="_blank" <img src="http://www.xxyy.com/h4...."/> ></a>`
Please see how can I make input to show links in value instead of images.
You should use htmlspecialchars for whatever sets the value= of those <input type="text"> boxes.
It will take image tags and HTML and render them as HTML entities that will safely be place in that text box.
Then when you want to process the contents of that for, just use html_entity_decode to decode the HTML entities.
UPDATE: Your first attempt to fix this—shown in the comments—is this:
<input name="addtop" type="text" value="htmlspecialchars(<?php echo $addtop?>)" />
That is just incorrect. htmlspecialchars is a PHP function. So you need to put it in the <?php … ?> area. It should be:
<input name="addtop" type="text" value="<?php echo htmlspecialchars($addtop)?>" />

Display text "loading..." after file is selected in input type="file" element

I am using a really simple form to allow users to upload files to my server. It works well, but i have noticed that even for very small files, right after selecting the file to upload, it takes a while (2-3 sec) to change the "No file selected" to the actual name of the file selected. (Actually it says it in spanish - guess somebody knows where i am).
The thing is that during this loading time the mouse wheel nor the browser look like they are thinking, so im afraid the user wont be patient enough and will feel its not working.
So i just want to display a text saying, "hey, hold on - its loading" And this is what i have tried with no luck:
A.
<input type="file" name="userf" onload="function(e){e.innerHTML='Loading';};">
</input>
B.
<input type="file" name="userf" onchange="function(e){e.innerHTML='Loading';};">
</input>
C.
<input type="file" name="userf" onload="function(){this.innerHTML='Loading';};">
</input>
D.
<input type="file" name="userf" onchange="function(){this.innerHTML='Loading';}">
</input>
If this is not possible, could i not just change the default message: "No file selected"?
EDIT
If possible, no JQuery, just javascript
You cannot change the default text on an input file element. But you can do some work arounds in order to get something similar you want. It may require jQuery or other framework to do the job.
This post may help: How to change the button text of <input type="file" />?

Upload File - Customizing Html

How can I do to browse my files when i click in a button "Upload" ?
I need to create a hidden file input?
More Explain:
I can't edit css of input type file of my html forms. So in each browser I have a different layout. I don't want it. I want to customize my form.
I created a button. When I click on the button, I want to appear the file selection screen.
When I select the file and press ok , I want to put the path string of my file in the input that I created.
Could you provide more information? You need to use the file html form element.
The file element lets you browse your local documents naturally.
To process the file attachment you need to know a programming language like php
I solved my problem with this code:
<div class="input-append">
<label for="showpath">File Upload:</label>
<input id="showpath" type="text" onclick ="javascript:document.getElementById('CommentFile').click();"/>
<button type="button" onclick ="javascript:document.getElementById('CommentFile').click();"></button>
<input type="file" name="data[Comment][file]" id="CommentFile" style='visibility: hidden;' onchange="updateInput(this.value,'showpath')"/>
</div>
<input type='file' />
More info at w3schools.

Automatically submitting a form when an upload file is chosen

I have a HTML page with the following input tag:
...
<input type="file" id="browseContactImageButton" />
...
Clicking the button on the page results in Open File Dialog. If I want to do the actual uploading, I need another button to click (submit), because this input file button is used just to provide the path to the file.
Is it possible to click the browse button, select the file and to start the uploading function immediately after the file has been chosen? If yes, could anyone provide the code snippet? Thanks.
If you want the form to submit after the user has made their selection, then simply add
<input type="file" onchange="this.form.submit();" ..... >
I had the same requirement.
I figured out to use onchange event of fileupload control to fire c# method.
But I'm getting FileUpload1.HasFile property always 'False' and file name was not set yet.
My markup:
<asp:FileUpload ID="FileUpload1" runat="server" ClientIDMode="AutoID"
ViewStateMode="Enabled" onchange="UploadImage();"/>
any suggessions?

Categories