Im trying to upload a file through a form to my php server and then display the name of the file. ATM I'm getting an error when I'm trying to submit the form:
Objekt was not found! Error 404
<html>
<body>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="file" size="35">
<br>
<br>
<input type="submit" value="Upload" name="submit">
</body>
</html>
<?php
header('Content-type: text/plain');
if(isset($_FILES["file"])){
$file = $_FILES["file"];
echo("File: ".$file);
}
?>
if you want to upload/do any operation on same file then remove action from form. then change your code as below to echo file name
<html>
<body>
<form method="post" enctype="multipart/form-data" >
<input type="file" name="file" size="35">
<br>
<br>
<input type="submit" value="Upload" name="submit">
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if(isset($_FILES["file"])){
$file = $_FILES["file"]["name"];
echo "File: ".$file;
}
}
?>
Related
i am a noob in php i cant display the image data in php. im trying it for 1hr but cannot understand the problem. please help.
<?php
ini_set('mysql.connect_timeout',300);
ini_set('default_socket_timeout',300);
?>
<form method="post" enctype="multipart/form-data">
<br/>
<input type="file" name="image"/>
<br/><br/>
<input type="submit" name="submit" value="Upload"/>
</form>
<?php
if(isset($_POST['submit'])
{
$imagedata=mysql_real_escape_string(file_get_contents($_FILES["image"],["tmp_name"]));
echo $imagedata;
}
else
{
echo "there has been some error";
}
?>
</body>
Fixed code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
<?php
if(isset($_POST['submit'])) {
$imagedata=file_get_contents($_FILES["image"]["tmp_name"]);
echo $imagedata;
} else {
echo "there has been some error";
}
?>
</body>
</html>
However, this will just put out the binary data. If you want to actually show the image, you will have to do quite a bit more...
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>
I'm trying to upload files to my server but it doesn't work at all. Here is test code:
<?php
echo count($_FILES['upload']['name']);
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
<br>
<input type="submit" value="Upload">
</form>
</body>
</html>
It always prints 0, file upload is enabled on my server.
The problem is that you're not counting the $_FILES['upload'].
Simple fix for your problem
Use:
echo count($_FILES['upload']);
Instead of:
echo count($_FILES['upload']['name']);
Edit:
Remove [] from the input's name.
<?php
echo count($_FILES['upload']);//only this modified//
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
<br>
<input type="submit" value="Upload">
</form>
</body>
</html>
I have a form where i want to upload files with multiple inputs.My form looks like:
<form action="" method="post">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
I do not know how to process this form..
You form doesn't work until you don't include 'enctype="multipart/form-data"', because it is necessary to use input type file.
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
Now browse the file and submit the form. You will get all file data inside $_FILES. so to check what you get inside the file data, you can use :
echo '<pre>';
print_r($_FILES)
I'm not sure whether you have gone through the tutorials before, however below is the code which will help you to process it.
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
If you upload the file, you can get the files from,
$_FILES global array, i.e. $_FILES['tax'] and $_FILES['ta'].
More info can be found on php.net
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
<?php
//print_r($_POST);
if(isset($_POST['submit'])){
$name = $_FILES['tax']['name'];
$name1 = $_FILES['ta']['name'];
$temp_name = $_FILES['tax']['tmp_name'];
$temp_name1 = $_FILES['ta']['tmp_name'];
var_dump($_FILES);
if(isset($name)){
if(!empty($name)){
var_dump($_FILES);
$location = 'images/'.$name;
if(move_uploaded_file($temp_name, $location)){
echo 'File uploaded successfully';
}
}
} else {
echo 'You should select a file to upload !!';
}
if(isset($name1)){
if(!empty($name1)){
var_dump($_FILES);
$location = 'images/'.$name1;
if(move_uploaded_file($temp_name1, $location)){
echo 'File uploaded successfully';
}
}
} else {
echo 'You should select a file to upload !!';
}
}
?>
The submit form does not seem to pass along the uploaded file. The code is supposed to display "array" when a file is uploaded. Nothing happens when submit is pressed
<?php
$conn = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db ('coop',$conn);
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,"r");
while(($fileop = fgetcsv($handle,1000,"|")) !== false)
{
echo $fileop;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
</head>
<body>
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="file" name="file" />
</form>
<br />
<input type="submit" name="submit" value="submit">
</body>
</html>
Your <form> </form> tag should wrap all elements of the form. Like the following:
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="file" name="file" />
<br />
<input type="submit" name="submit" value="submit">
</form>
Your submit is outside of the form tags, Fix your HTML and the posting should work.