file array output printing - php

i am using an array of file, i mean input type ="file" to upload number of files at a time.
i want to print or echo that file array values , how can i do this.
please help me
Thanks

You can create an array by suffixing [] to the name of the field:
<from method="POST" enctype="multipart/form-data">
<input type="file" name="myfile[]" />
<input type="file" name="myfile[]" />
<input type="file" name="myfile[]" />
<!-- and so on -->
<input type="submit" name="submit" value="Submit" />
</form>
PHP
if (isset($_POST['submit']))
{
print_r($_FILES['myfile']);
}

Do you mean this?
var_dump($_FILES['myfield']);

Related

Multiple Images from separate input fields with php ajax

How to insert and update multiple images from multiple input fields in one form with PHP Ajax.
For example:
<form>
<input type="file" name="img1">
<input type="file" name="img2">
<input type="file" name="img3">
<input type="submit" value="Save">
</form>
Put your input name into an array.
<form>
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="submit" value="Save">
</form>

Submitting an image alongside a form with one button

I have a regular form which submits to my database but I want to include a file upload in the form, so as to receive the form input in the expected table using PHP post and also receive the uploaded image.
Use <input type="file"> to include a file upload in the form.
Use something like this to send Files as well as other inputs to the processing page where you can access files and post variables.
<form action="#" method="post" enctype="multipart/form-data">
<input type="text" name="txtbox">
<br />
<input type="file" name="filebox">
<br />
<input type="submit" name="submit" value="submit">
</form>
When this is submitted you can access the data from $_FILES and $_POST
There are various input types in HTML just as the below:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
Each of the above inputs demand different conditions and formats to be satisfied.
For your query the answer is either:
<input type="file">
For webpages that require inputs in a file format. Or,
<input type="image">
For webpages requiring input in an image format.
For further details view the below link for help:
https://www.w3schools.com/html/html_form_input_types.asp

Put input value back to input filed

I have two submit buttons in one form and when I used the first submit, all the text input fields become blank. I try to solve this by using a session to store the textfield inputs.However, I don't know how I can put back the value to the input field that I stored in the session after the first submit is used.
The HTML code:
<form method="post" enctype="multipart/form-data">
<input type="text" name="headline" id="headline" required />
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Images" name="submit_image">
<input type="submit" name="submit_post" value="Submit Your Post"/>
</form>
The php code:
<?php
session_start();
if (isset($_POST["submit_image"])) {
if (!empty($_POST['headline'])) {
$_SESSION["headline_session"] = $_POST ["headline"];
}
}
$headline_session = $_SESSION["headline_session"];
?>
Why you want to use a session!
you can echo the value of $post parameter in a property called (value) like this
<form method="post" enctype="multipart/form-data">
<input type="text" name="headline" id="headline" value="<?php echo $_POST ['headline']; ?>" required />
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Images" name="submit_image">
<input type="submit" name="submit_post" value="Submit Your Post"/>
</form>
You can still save things to session if you need them later but I recommend just echoing out the previous value.
<form method="post" enctype="multipart/form-data">
<input type="text" name="headline" id="headline" value="<?php echo $_POST['headline']; ?>" required />
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Images" name="submit_image">
<input type="submit" name="submit_post" value="Submit Your Post"/>
</form>
Should you need to compare the previous submissions with what was already submitted then this is one way to do it.
Good work thinking forward :) happy coding

var_dump only shows 1 array when upload more than 1 file

i have a script that uploads images and then crops them. but when i use
<input type="file" name="filename" multiple="multiple"/><br />
and then do a var_dump i only get 1 array instead of 'for example' 10 images.
My uploadform:
<form action="uploaded.php" method="POST" enctype="multipart/form-data">
<hr>
<input type="file" name="filename" multiple="multiple"/><br />
<br /><br />
<hr width="60" align="left">
<input type="submit" value="Upload" />
</form>
My code to see the uploades files:
<?php
session_start();
echo "<pre>";
var_dump($_FILES);
die();
?>
when i upload 10 images. it only shows the first selected and prints out 1 array.
Please help!
Thanks
EDIT: i think that i have to use a session for this. but how do i do that?
Same as any other form element used more then once: <input type="file" name="filename[]" multiple="multiple"/>

How to send iframe id/name to a php file?

I have a iframe with a name, in this case an email address that changes from users.
I need to deal with this var:
<iframe name="asd#asd.lol" src="index.html">
index.html is a simple data form like this:
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>
I need to pass the value "asd#asd.lol" to the "upload.php" file.
Is this possible?
Is it possible for you to add a querystring parameter into the index.html file?
So:
<iframe name="asd#asd.lol" src="index.html?email=asd#asd.lol">
Then in the index.html file set a hidden variable:
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="hidden" name="email" id="email" value="">
<input type="submit" value="Upload">
</form>
If this is a plain HTML file you could set the value of the hidden field with some javascript.
Then use $_POST["email"] to get the email value out of the hidden field.
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST" onsubmit='$(this).append('<input type="hidden" name="iframeEmail" value="'+$("iframe[src='index.html']").attr('name')+'">')'>
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>
Try this out ,if it wont work ,than place the iFrame and ID and find it with the ID on jQuery Selector

Categories