So I have a very simple file upload form, code below...
<form enctype="multipart/form-data" action="$theaction" method="POST">
<input name="source" type="file">
<input name="message" type="text" value="">
<input type="submit" value="Upload"/>
</form>
I was wondering if I can set with php the source of the file upload? Something like..
<?php $file = "http://mywebsite.com/path/to/img.jpg"; ?>
<input name="source" type="file" src="<?php echo $file; ?>">
I've googled it but I can't come up with anything. I feel like I'm just not using the proper vocabulary, but any help would be greatly appreciated!
I concur #IMSoP statement.
Instead of populating the input tag value, I would rather create an element (div) to display the thumbnail version of the image that was uploaded by the user that way it makes it clear to the user that a file exist and also I would give them the option to edit for uploading a new file & delete for deleting the file.
Related
I have a huge form that lets users (along with a lot of other inputs) upload multiple images, like this:
<input type="file" id="product_images" class="hidden" name="upload[]" multiple>
<input type="file" id="product_images_2" class="hidden" name="upload[]" multiple>
...
Now, when there is an error in a certain input (e.g. String for "description"-field too short), the page reloads. After this reload I need to keep all the posted data in all the inputs. For a text input I know how to do it, like this:
<input name="name" type="text" value="<?php echo $_POST['name']; ?>"/>
but, how can I achieve this for the file inputs?
I tried something like this:
<input type="file" id="product_images" name="upload[]" multiple value="<?php print($_POST['upload']); ?>">
Did not work though. Any ideas? Thanks!
Maybe that's because you are validating in server, try to validate your field in browser, if the server reloads it will loose all your data saved in fields.
Try this validator personally i like it:
http://jqueryvalidation.org/
Hop it helps
$_SESSION["image_path"] = $_POST['upload'];
<input type="file" id="product_images"<?php values= if(empty($_session['image_path'])) {} else { echo $_session['image_path']; } ?>class="hidden" name="upload[]">
after you retrieved ,Destroy the session
Try to use pattern in your input bar that will help you , you can do it very easily
http://www.wufoo.com/html5/attributes/10-pattern.html
http://www.w3schools.com/tags/att_input_pattern.asp
Hello I needed code for automatically chose file and upload it to desired link. How to do that?
html code:
<html>
<head><title>Uploading</title></head>
<body>
<form method="post" enctype="multipart/form-data" action="uploadFile.php">
<input type="file" name="file" id="file">
<input type="submit" value="Submit">
</form>
</body>
</html>]
In above code at this line
<input type="file" name="file" id="file">
this path is fixed and can't be changed as user tries. so when user click on "Submit" button the file has to upload.
How to do this?
TL;DR: What you are trying to do is absolutely impossible - for a good reason.
If this was possible, you could create a hidden upload field pointing to a file containing valuable data (e.g. the browser's cookie database) and submit the form using JavaScript (or make the user submit it without knowing about that upload) and copy any file the user has access to.
simple question this time around...
So I have this code I managed to find and it works well for me. But I would like to add to it a thumbnail display of the image upon submission. Could anyone help me to figure out the code and how it will fit in to display a thumbnail? Please and thanks everyone.
Here is the jsfiddle for it.
HTML:
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data">
File: <input type="file" name="file" style="width: 250px;"><br>
<input type="submit" name="submit" value="Upload File">
</form>
Just make and <img> tag with attribute src="$link" where $link is the link to the image.
I am using this code to make a upload-form for my website.
Youtubeuploader
It works perfect, but I got ONE problem.
I want a form to define the title.
Right now, all the videos are given the title "Example"
I want the user to write their own title for their video.
I've tried making a input with id and name "title", and tried to use $_POST['title'], but it didn't work. The video didn't even upload.
Anyone knows how to do this?
I've looked at all the YouTube Data API code and tried everything.
Thanks.
Given the link you posted, you have to give $youtube_video_title the value from your form.
I mean like this (not secure, always sanitize and filter):
$youtube_video_title = $_POST['title'];
UPDATE :
try to replace the form code with this one
<form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data" onsubmit="return checkForFile();">
Title : <input id="title" type="text" name="title"/>
<input id="file" type="file" name="file"/>
<div id="errMsg" style="display:none;color:red">
You need to specify a file.
</div>
<input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
<input type="submit" value="go" />
</form>
I keep getting an error:Notice: Undefined index: on line 35
line 35:
$handle = new Upload($_FILES['my_field']);
this is my input field
<input type="file" size="32" name="my_field" value="" />
I do not understand this error, thanks!!!
EDIT:
<form name="upload" id="upload" enctype="multipart/form-data" method="post" action="actions/upload.php" />
<p><input type="file" size="32" name="my_field" value="" /></p>
<p class="button"><input type="hidden" name="action" value="image" />
<br>
<input style="margin-left:224px;" type="submit" name="submit" value="upload" />
Update: The OP is doing an Ajax request - well that obviously can't work with a File upload.
Old answer:
I think I found it.
Look closely at this tag:
<form name="upload" id="upload" enctype="multipart/form-data" method="post"
action="actions/upload.php" />
the closing /> closes the form. Everything that comes afterwards, is not inside that form - it's inside a new one that the browser probably generates to deal with the broken markup. That new form is not enctype=multipart/form-data.
Did you use enctype="multipart/form-data" on the form element?
This seems to be the only reason that the the key my_field isn't set on $_FILES.
Edit: If your file is bigger than post_max_size, you also get an empty $_FILES array.
See also: Apache/PHP: $_FILES Array mysteriously empty
In order to upload WITH an ajax submission you can use an IFRAME with the upload part in there.
Send ajax form submission
Using javascript trigger submit() on the upload form in the IFRAME
Have the returning page in the iframe trigger a javascript complete response function in the main page
A bit complicated but would work. You would need some mechanism to tie them together, for instance if you are submiting info about the image, have step 1 return the id of the database row where that info is stored so that the IFRAME upload form can submit that id so it knows where to store the picture.