Cannot display content of $_FILES - php

Have a look at the following code:
<?php
if (isset($_POST['email']))
{
$expertmail=trim($_POST['email']);
echo $expertmail;
$expertfile=$_FILES['upfile']['tmp_name'];
echo $expertfile;
}
?>
<form action="test.php" method="post" name="users" id="users" >
<input name="upfile" id="upfile" type="file" />
<input name="email" id="email" type="text" />
<input type="submit" name="submit_button" id="submit_button" value="ΑΠΟΣΤΟΛΗ" />
</form>
Why 'echo $expertfile' does not display anything?
Thank you

POST Method Uploads gives all the information you need to handle file uploads in PHP. For your case you need: enctype="multipart/form-data":
<form action="test.php" method="post" name="users" id="users" enctype="multipart/form-data">
As Salman A points out, you will also need to check to see if a file was uploaded.

Related

Pass variable PHP/HTML

Need to pass variable from actual site like this
<form id="form" action="Atest.php" method="post" enctype="multipart/form-data">
name: <input name="name" value="" id="name" /> <br />
**<a href='Atest.php?searchname=<?php $_GET['name'];?>'>**GO</a>
</form>
The part searchname= isn t working.
Problem still staying after SET/SET or GET/GET fix
Page throwing :
/Atest.php? searchname= Notice:%20%20Undefined%20index:%20name%20in%20C:\xampp\htdocs\PhpProject3\Atest.php%20on%20line%2032
fULL CODE
<?php
function runMyFunction(){ echo "DONE";
}
if (isset($_GET['searchname'])) {
runMyFunction();
}
?>
<html><head></head>
<body>
<div class="sas">
<form id="form" action="Atest.php" method="post" enctype="multipart/form-data">
Heslo: <input name="name" value="" id="name" /> <br />
<a href='Atest.php?searchname=<?php $_POST['name'];?>'>Run PHP Function</a>
</form></div></body></html>
The closest I can think you mean is like this:
<?php
function runMyFunction(){
echo "DONE";
}
if ( isset( $_GET['searchname'] ) ) {
call_user_func('runMyFunction');
}
?>
<html>
<head></head>
<body>
<div class="sas">
<form id="form" method="get" enctype="multipart/form-data">
Heslo: <input name="searchname" value="" id="name" /> <br />
<input type='submit' value='Run PHP Function'>
</form>
</div>
</body>
</html>
You could alternatively use a textual link and assign a javascript function to it that submits the form.
You have to do this following way:
<form id="form" action="Atest.php" method="get" enctype="multipart/form-data">
name: <input name="searchname" value="" id="name" /> <br />
<button type="submit">**GO</button>
</form>
This code will throw you an error. you are mixing POST and GET.
<form id="form" action="Atest.php" method="post" enctype="multipart/form-data">
name: <input name="name" value="" id="name" /> <br />
****GO
Before you use GET or POST, make sure you check for the value.
if(isset($_GET['name']){
// your stuff here
}
you can try this one:
<a href='Atest.php?searchname=<?php $_GET['name'];?>'>**GO</a>

Cant get variables via _post IF form Has a name, like form3

i discovered, if a form has aname in html, i cannot get variables via $_post .
Example;
<form action="" name="form1" method="POST" accept-charset="UTF-8">
<input type="checkbox" name="checkbox_1" value="1">
</form>
<form action="" name="form1" method="POST" accept-charset="UTF-8">
<input type="text" name="e_mail" />
</form>
<?php
$e_mail= $_POST['e_mail'];
echo "$e_mail";
?>
no matter what i did , didint work.
in the end i deleted that "name=form1" and joined the 's together .. like this;;
<form action="" method="POST" accept-charset="UTF-8"> //deleted name=form1
<input type="checkbox" name="checkbox_1" value="1">
<input type="text" name="e_mail" />
</form>
magically WORKED!! (happy).. dont know why? but it worked..
i just wanted to help if anyone comes across with this NON-ERROR_giving annoyance.
and this is happening When i use dreamWeaver to create table. what a devil dreamWeaver are you.. you really eat all my youth.
<form action="" name="form1" method="POST" accept-charset="UTF-8">
<input type="checkbox" name="checkbox_1" value="1">
<input type="text" name="e_mail" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['e_mail'])){
echo "$e_mail";
}
?>
php will throw an error the way you have it. Also, you would only need 2 forms if you are going to have them process differently.

How can I make photo change once uploaded with this form

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>

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

Tomcat 6 & PHP with enctype - No input data returned

I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);

Categories