I am trying to check the size of my file using echo $_FILES['photo']['size'] but nothing is being returned.
HTML
<form method="POST" action="sendToDatabase.php">
<fieldset>
<legend>Artwork</legend>
<label>Album Artwork</label>
<input type="file" name="art" />
<p>
File must be saved as a .jpg file.<br />Please crop to 150px wide X 200px tall before uploading.
</p>
</fieldset>
<input type="submit" name="submit" value="Submit Album" class="submitBtn" />
</form>
PHP
<?php echo $_FILES['art']['size']; ?>
you need to add enctype="multipart/form-data" into form tag
enctype="multipart/form-data"
<form method="POST" action="sendToDatabase.php" enctype="multipart/form-data" >
Related
I am uploading a picture, but isset() returns false even when I clearly picked a file. Here is my code.
<form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="addroom.php">
<p>Upload pictures:</p>
<p>Bed:</p>
<input type="file" name="image1"/>
<p>Comfort room</p>
<input type="file" name="image2"/>
<p>Living room:</p>
<input type="file" name="image3"/>
<input type="submit" id="add" name="add" value="Add Room Category"/>
</form>
<?php
if(isset($_POST['image1']))
$file1=$_FILES['image1']['name'];
else
echo "image not selected";
Uploaded files are stored in $_FILES. $_POST['image1'] does not exist because that is a file, not a text (or other) field.
You want to use either:
if(isset($_POST['add']))
or
if(isset($_FILES['image1']))
Try this
if(isset($_FILES["image1"]["name"])){...}
In html I have an upload button for a photo:
<p>
<input type="file" name="datafile" size="40">
</p>
<br>
<p>
<input type="submit" name="submit" id="submit" value="submit" />
</p>
After that I want to take the results using the echo and insert the result in a table in the center of page.
I made this but it is not working properly. Any suggestion?
<table align="center">
<tr>
<?php echo $_POST['datafile']; ?>
</tr>
</table>
Your code should be
<?php
if(isset($_POST['submit'])){
print_r($_FILES); // you will get your data in $_FILES variable.
}
?>
<form action="file_upload.php" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="datafile" size="40">
</p>
<br>
<p>
<input type="submit" name="submit" id="submit" value="submit" />
</p>
</form>
You should have enctype="multipart/form-data in your form tag
<form action="upload.php" method="post" enctype="multipart/form-data">
And get the uploaded file via $_FILES: http://www.w3schools.com/php/php_file_upload.asp
$_FILES['datafile']
Read more here http://www.w3schools.com/php/php_file_upload.asp
I am attempting to upload multiple images at once, and then on submit display those images on the page. This is going to be used with mPDF. I am using the examples in the manual at http://mpdf1.com/manual/index.php?tid=467
It has a text box and 1 image uploader, and displays what ever was in the text box and the image on the next page. How can I convert this to use multiple images?
Page 1:
<?php
$html = '
<html>
<body>
<form action="example_userinput2.php" method="post" enctype="multipart/form-data">
Enter text:
<br />
<textarea name="text" id="text"></textarea>
<br />
<label for="file">Choose Image to upload:</label> <input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
';
echo $html;
exit;
?>
Page 2: (also more specifically what I change the areas I marked ** **, after allowing multiple images.)
<?php
if (($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg")
& $_FILES["file"]["size"] < 20000) {
// If the destination file already exists, it will be overwritten
move_uploaded_file($_FILES["file"]["tmp_name"], "../tmp/" . $_FILES["file"]["name"]);
}
else {
echo "Invalid file";
}
$html ='
<html>
<body>
<div>'.$_POST['text'].'</div>
**<img src="' ."../tmp/" . $_FILES["file"]["name"].'" />**
<form action="example_userinput3.php" method="post" enctype="multipart/form-data">
<textarea style="display:none" name="text" id="text">'.$_POST['text'].'</textarea>
**<input type="hidden" name="filename" id="filename" value="'. $_FILES["file"]**["name"].'" />
<input type="submit" name="submit" value="Create PDF file" />
</form>
</body>
</html>
';
echo $html;
exit;
?>
Page 3 goes to the mPDF generator so I can convert this to PDF for another project I have in mind.
Any help would be awesome.
From php manual, to find here: http://php.net/manual/en/features.file-upload.multiple.php
<form action="example_userinput2.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
On page2, you can continue with a loop and handle those files at once:
foreach ($_FILES['array_of_files'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
var_dump($file);
}
You can do the same as with one file in the loop
You can have multiple <input type="file"> html elements set up on your page set up this way:
<input type="file" name="file[0]" />
<input type="file" name="file[1]" />
etc.
And then in PHP loop through them:
foreach($_FILES['file'] as $file){
//refer to everything as $file instead of $_FILES['file']
}
That should be enough to get you started.
I am trying to work around this, I know it might need mysql, php or something but i will like to know how i can make the imageuploaded.jpg in this html change anytime a new one is uploaded with the html form below? before voting the question down please give a suggestion at least. I am new to html
<fieldset>
<legend>User Photo </legend>
<p align="center"><img src="imageuploaded.jpg" /></p>
</fieldset>
</td>
<form name="" method="post" enctype='multipart/form-data'>
<input id="browse" type="file" name="image">
<input id="upload" type="submit" name="Submit"value="upload" />
</form>
<form name="insert" method="post">
<p>
You can use something like this:
<?php
if ($_POST && $_FILES['image']['name']) {
$avatar = $_FILES['image']['name'];
} else {
$avatar = "noimage.jpg";
}
?>
<fieldset>
<legend>User Photo </legend>
<p align="center"><img src="<?php echo $avatar;?>" /></p>
</fieldset>
</td>
<form name="" method="post" enctype='multipart/form-data'>
<input id="browse" type="file" name="image">
<input id="upload" type="submit" name="Submit"value="upload" />
</form>
<p>
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"/>