I need to move the image from temporary location to some other directory .
The input form is defined as follows:
<form action="#" method="post" id="rent_details" name="rent_details" enctype="multipart/form-data">
Upload Image :<input type="file" name="fileToUpload" id="fileToUpload">
type:- <select name="spottype" id="spottype">
<option value="xxx">xxx</option>
<option value="yyy">yyy</option>
<option value="zzz">zzz</option>
</select>
<input type="submit" id="bidm" name="bidm" value="Next"/>
</form>
I have following code for move the file ,
$target_dir = "./spotimages/";
$tmp_name = $_FILES["fileToUpload"]["tmp_name"];
$name = $_FILES["fileToUpload"]["name"];
$move_to=$target_dir.$name;
move_uploaded_file($tmp_name, $move_to);
Here,The files doesn't move spotimages folder. How to solve this. Please help me.
hi did you put this enctype="multipart/form-data" in your form tag
<form action="your_file.php" method="post" enctype="multipart/form-data">
......
......
......
</form>
Related
I'm trying to take posted input file name, I'm not uploading anywhere.
I just need the name of posted filename so I'm trying this code;
<form method="post" enctype="multipart/form-data" role="form">
<input type="file" id="file" name="file">
<input type="submit" name="submit" value="Submit Form">
</form>
<?php
if(isset($_POST['submit'])){
echo $_FILES['file'];
}
?>
If I change enctype="multipart/form-data" into form tag, it's ok, but I need this tag.
You still need the enctype attribute, as the files will not be available without it.
if (isset($_POST['submit'])) {
echo $_FILES['file']['name'];
}
use
echo $_FILES['file']['name'];
instead of
echo $_FILES['file'];
$_FILES['file'] contains array of properties of uploaded file. use print_r instead. It will work fine.
you can get file name like that
$name = $_FILES['file']['name'];
this code is working fine
<form method="post" enctype="multipart/form-data" role="form">
<input type="file" id="file" name="file">
<input type="submit" name="submit" value="Submit Form">
</form>
<?php
if(isset($_POST['submit'])){
echo "<pre>";
print_r($_FILES['file']) ;
}
?>
I know there's questions on this issue but I'm trying to get images uploaded to a directory using move_uploaded_file. I'm using the example from the php manual http://www.php.net/manual/en/function.move-uploaded-file.php but I'm getting an Undefined index: file. File is the name of my file input type so I'm not sure why it's undefined.
Here is my form:
<form action="MoveImages.php" class="dropzone" id="my-awesome-dropzone" method="post">
<input type="file" name="file" />
<input TYPE="submit" name="upload" title="Add Images" value="Add Photo"/>
</form>
Here's my PHP file:
<?php
$uploads_dir = '/Users/Jane/Desktop/NE';
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
?>
Can anyone see where I am going wrong?
Add enctype="multipart/form-data" in your form tag.
That attribute is required when you are uploading file.
I made theform working with storing the images directly on database and now, I want to learn how to store them in a folder, and store in database just the path.
At this moment I get this error Notice: Undefined index: uploaded_file in and I really don't understand why. Please, some F1 :)
Html form:
<form action="ad_cont.php" method="POST" class="add_contact" name="add_contact" enctype="multipart/form-data">
<input type="file" name="uploaded_file" multiple required>
<input type="submit" value="Upload" class="button">
</form>
Php script:
$img_path = "images/avatar";
$img_path = $img_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $img_path)) {
mysqli_query($conn,"INSERT INTO `uploads` (filename,path)
VALUES ('".$_FILES['uploaded_file']['tmp_name']."','".$img_path."')");
You have to add enctype='multipart/form-data' to your form for file uploads to work.
<form action="ad_cont.php" method="POST" class="add_contact" enctype="multipart/form-data" name="add_contact">
<input type="file" name="uploaded_file" multiple required>
<input type="submit" value="Upload" class="button">
</form>
The change php code like this.
$img_path = "images/avatar";
$img_path = $img_path . basename( $_FILES['uploaded_file']['name']);
$img_name= $_FILES['uploaded_file']['tmp_name'];
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $img_path)) {
mysqli_query($conn,"INSERT INTO `uploads` (filename,path)
VALUES ('".$img_name."','".$img_path."')");
Try changing the code of your form like this and hope it will work then.
To upload file to server, you need to mention enctype='multipart/form-data' in the <form>
<form enctype="multipart/form-data" action="ad_cont.php" method="POST" class="add_contact" name="add_contact" >
..
..
</form>
Hi Hi trying to upload a file via a form move it to another folder and then print its name. But doesnt work don't know why.
<form method="post" action='exercice.php' id="form1">
<input type="file" name="files" id="files" onChange="submitForm();">
</form>
<?php
if (isset($_FILES['files']))
{
move_uploaded_file($_FILES['files']['tmp_name'], "uploaded/");
echo $_FILES['files']['name'];
}
?>
form missing:
enctype="multipart/form-data"
ref:
spec
<form method="post" action='exercice.php' id="form1">
<input type="file" name="files" id="files" onChange="submitForm();">
</form>
<?php
if (isset($_FILES['files']))
{
move_uploaded_file($_FILES['files']['tmp_name'], "uploaded/".$_FILES['files']['name']);
echo $_FILES['files']['name'];
}
?>
You need to include the file name in the upload path, like shown above.
Also, where is your upload (ajax) code?
Did isset($_FILES['files']) return true?
I have an HTML web form where users can upload multiple files. I am having trouble with moving the files though.
HTML:
My HTML:
<form enctype="multipart/form-data" method="post" action="save.php">
<input type="hidden" name="MAX_FILE_SIZE" value="500000"/>
<input type="file" name="uploads[]" multiple="multiple" />
<input type="submit" name="submit" value="submit"/>
</form>
Save.php:
<?php
foreach ($_FILES['uploads']['name'] as $file) {
$target= UPLOADPATH . $file;
move_uploaded_file($file, $target)
or die('error with moving the file');
$file= time() . $_FILES['uploads']['name'];
echo $file;
}
What could I be doing wrong?
You have to use $_FILES['uploads']['tmp_name'] instead of $_FILES['uploads']['name'] for moving the file. name is the original file name but tmp_name is the current uploaded file path.