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>
Related
I have looked all over stackoverflow and have not yet found a working answer.
The HTML form allows the user to upload multiple files using one single input, the values then travel to a php file (named upload.php) to be uploaded to their final resting place.... this doesn't happen.
My HTML form:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="upload[]" type="file" multiple="multiple" />
<input type="submit" value="Upload Files" class="btn btn-default btn-sm"/>
</form>
My PHP file:
<?php
if(count($_FILES['upload']['name'])) {
foreach ($_FILES['upload']['name'] as $file) {
move_uploaded_file($_FILES["upload"]["tmp_name"], './uploads/'.$_FILES["upload"]["name"]);
}
}
?>
try this code
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="upload[]" type="file" multiple="multiple" />
<input type="submit" name="submit" value="Upload Files" class="btn btn-default btn-sm"/>
</form>
Your PHP file
<?php
if(isset($_POST["submit"]))
{
if(count($_FILES['upload']['name'])) {
foreach ($_FILES['upload']['name'] as $key=>$file) {
move_uploaded_file($_FILES['upload']['tmp_name'][$key], './uploads/'.$file);
}
}
}
?>
I have edited this answer and below code is working for me.... hope this will help.
<!DOCTYPE HTML>
<html>
<body>
<form method="post" action="" enctype="multipart/form-data">
<input name="upload[]" type="file" multiple="multiple" />
<input type="submit" name="submit" value="Upload Files" class="btn btn-default btn-sm"/>
</form>
<div>
<?php if(isset($_POST['submit'])){
foreach($_FILES['upload']['name'] as $key=>$filename){
move_uploaded_file($_FILES["upload"]["tmp_name"][$key], '.pathtoupload/'.$filename);
}
}?>
</div>
</body>
</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>
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
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.
I have a form that is written in PHP that will call the page upon itself (I don't know if I say this right).
echo('</table>
<hr>
<h1 id="loadscript_h1">Voeg een loadscript toe</h1>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" enctype="multipart/form-data">
<div><input type="file" name="loadscript" id="loadscript" value="Kies loadscript"/></div>');
echo ('<input type="submit" class="formsubmit" name="upload_loadscript" value="Upload loadscripts" />
</form>');
But when I look at my website there is something written like this:
" method="POST" enctype="multipart/form-data">
How can I write this properly?
you have to use concatenation for strings. notice the '. which tells PHP to terminate string, then concatenate with the following. See the docs: http://www.php.net/manual/en/language.operators.string.php
echo '</table>
<hr>
<h1 id="loadscript_h1">Voeg een loadscript toe</h1>
<form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="POST" enctype="multipart/form-data">
<div><input type="file" name="loadscript" id="loadscript" value="Kies loadscript"/></div><input type="submit" class="formsubmit" name="upload_loadscript" value="Upload loadscripts" />
</form>';
also, you don't need parenthesis for echo.
Using PHP Heredoc
$action = htmlspecialchars($_SERVER["PHP_SELF"]);
$form = <<<FORM
</table>
<hr>
<h1 id="loadscript_h1">Voeg een loadscript toe</h1>
<form action="{$action}" method="POST" enctype="multipart/form-data">
<div><input type="file" name="loadscript" id="loadscript" value="Kies loadscript"/></div>
<input type="submit" class="formsubmit" name="upload_loadscript" value="Upload loadscripts" />
</form>
FORM;
echo $form;
You can also just leave the action field empty and the form will submit back to itself when posted.