This question already has answers here:
Why would $_FILES be empty when uploading files to PHP?
(22 answers)
Closed 8 years ago.
Regarding this ...... question but......... still learning :3
so i have a php file lets say called x.php and all working i would like to add uploader so people can upload txt files ....... but i dnt want to have another file which is uploader.php
Thnx in advance......
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<center>
upload ur CV.<br>
<form action="same.php" method="post"><br>
<input type="file" name="uploadFile">
<input type="submit" value="Upload Wordlist">
</form>
</body>
</html>
</center>
<?php
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")
?>
Your form lacks "enctype="multipart/form-data" in
<form action="same.php" method="post"> which should read like this
<form action="same.php" method="post "enctype="multipart/form-data">
This is an essential part of uploading files.
Consult the manuals:
http://php.net/manual/en/function.move-uploaded-file.php
http://php.net/manual/en/features.file-upload.post-method.php
Plus, make sure that the folder is writeable and with proper permissions set.
Edit:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<center>
upload ur CV.<br>
<form action="" method="post" enctype="multipart/form-data"><br>
<input type="file" name="uploadFile">
<input type="submit" name = "submit" value="Upload Wordlist">
</form>
</body>
</html>
</center>
<?php
if(isset($_POST['submit'])){
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}");
}
?>
Related
I'm trying to upload an image and display after uploading, the upload part works fine but image can't display.
Any answers?
Code:
<!DOCTYPE html>
<html>
<body>
<?php
echo <<<_END
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fupload" size="100000" accept="image/*">
<input type="submit" name="upload" value="Upload">
</form>
_END;
if($_FILES){
$name = $_FILES['fupload']['name'];
move_uploaded_file($name = $_FILES['fupload']['tmp_name'], $name);
echo "<br><img src='$name'>";
}
?>
</body>
</html>
Browser:
Image can't display
nevermind, the problem is move_upload ($name=xxxx, $name), it means you assign to $name the tmp source !
here is a working code
<!DOCTYPE html>
<html>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fupload" size="100000" accept="image/*">
<input type="submit" name="upload" value="Upload">
</form>
<?php if($_FILES)
{
$source=$_FILES['fupload']['tmp_name'];
$target1 = $_FILES['fupload']['name'];
move_uploaded_file($source,$target1);
?>
<br>
source=<?php echo htmlspecialchars($source);?>
<br>
target=<?php echo htmlspecialchars($target1);?>
<img src="<?php echo htmlspecialchars($target1);?>"
<?php
} // if $_FILES
?>
</body>
</html>
Ok, following comment, it seems $name point To à path not accessible for external user. Try a link like this $name="c:\path To your base path\www\et.png"
Edit: supposing you have a existing www folder , where you find your index.php. It may be called public.
Why move_uploaded_file function does not work I have created a form in which I will upload some audio to the server folder but "move_uploaded_file" does not move the file. I don't know where I am wrong can please anyone help me.
<html>
<head>
</head>
<body>
<form action="uploading.php" method="post">
<input type="file" name= "audioFile"/><br>
<input type="Submit" value="Upload" name="Save_audio"/>
</form>
</body>
</html>
My HTML Code
uploading.php code
<?php
if(isset($_POST['Save_audio']) && $_POST['Save_audio']=="Upload")
{
$dir='Uploads/';
$audio_path=$dir.basename($_FILES['audioFile']['name']);
if (move_uploaded_file($_FILES['audioFile']['tmp_name'], $audio_path))
{
echo 'Uploaded';
}
}
?>
Don't assume a PHP function "doesn't work". Debug. In this case your browser isn't sending the file to the server at all.
Your form element is missing the encoding:
<form action="uploading.php" method="post" enctype="multipart/form-data">
Without the enctype the default encoding is application/x-www-form-urlencoded which can't hold files.
Because you are missed enctype="multipart/form-data" in form
<form action="uploading.php" method="post" enctype="multipart/form-data">
I'm trying to build a file upload form and I'm having trouble with the very basics. My form is this:
<html>
<body>
<form action="fileuploader.php" method="POST" enctype="multipart/form-data">
<input type="file" name="filename" />
<input type="submit"/>
</form>
</body>
</html>
My php code so far is one line and it doesn't do anything:
<?php
echo $_POST['filename'];
?>
The idea (at this point) is just to display the name of the file entered in the form. What am I doing wrong?
Based on your code I modified it. Have a try it.
HTML Part
<html>
<body>
<form action="fileuploader.php" method="POST" enctype="multipart/form-data">
<input type="file" name="filename" />
<input type="submit" name="submit" />
</form>
</body>
</html>
PHP
if (isset($_POST['submit'])) {
// Check if files array is not empty
if (!empty($_FILES)) {
$imageName = $_FILES['filename']['name'];
echo $imageName;
// Insert your code related to upload
}
}
You can print the filename using the following code:
<?php
echo $_FILES["filename"]["name"];
?>
I have a simple HTML file with a form to upload a file and PHP code to process the uploaded file. I've tried a bunch of input types and they all work except for input type="file". Nothing gets displayed. The code is attached.
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload:
<input type="file" name="test.f" id="test.f">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
The processing php code is:
<?php
echo "Hello world";
echo $_FILES["test.f"];
?>
you should call the file by name if it does not work please change the file name in your form
name="test"
$_FILES["test"]['name'];
Can someone please explain this code, i am following a very good book that was recommended to me and I have typed the code exactly as it is in the book. it displays the code instead of out, I am not sure what is wrong, the code is from a book called php solutions
<?php
// set the max upload size in bytes
$max = 51200;
if(isset($_POST['upload'])){
// define the path to the upload folder
$destination = 'C:\upload_test';
// move the file to the uplaod folder and rename it
move_uploaded_file($_FILES['image']
['tmp_name'], $destination.$_FILES['image']['setara']);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mult</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form action="" method="post" enctype="mutipar/form-data" id="uploadImage">
<p>
<label for="image">Upload image:</label>
<input type="hidden"name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
<input type="file" name="image" id="image">
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload">
</p>
</form>
</body>
</html>
This is surely because you are writing PHP code in .html or .htm extension file try putting the code with .php extension file. It will resolve error.