Having issue in multiple image upload? db image attached - php

<form name="property" action="" method="post" enctype="multipart/form-data">
Select Image
<input type="file" name="upload[]" multiple="multiple" id="image"/>
<input type="submit" value="Submit" name="submit" style="width:200px; height:30px;" />
</form>
MY Php code:
if(isset($_POST['submit']))
{
$total = count($_FILES['upload']['name']);
for($i=0; $i<$total; $i++)
{
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
if ($tmpFilePath != "")
{
$newFilePath[] = "upload/" . $_FILES['upload']['name'][$i];
$values_insert = implode(',', $newFilePath);
if(move_uploaded_file($tmpFilePath, $newFilePath))
{
$date=date("Y-m-d");
}
}
}
$d=mysql_query("INSERT INTO properties (iname,cdate) VALUES('".$values_insert."',NOW())") or die(mysql_error());
}
Note:
In database the path upload directory folder and image image is going to database, I want only image name separated by comma. for example the expected output is Chrysanthemum.jpg,Desert.jpg. I don't know what is the problem. please guide me.kindly look at my code and image attachment details.

Thing this'll do fyi - indenting code would help people read and help you.
if(isset($_POST['submit']))
{
$total = count($_FILES['upload']['name']);
for($i=0; $i<$total; $i++)
{
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
if ($tmpFilePath != "")
{
$newFilePath = "upload/" . $_FILES['upload']['name'][$i];
$newFilePath2[] = $_FILES['upload']['name'][$i];
$values_insert = implode(',', $newFilePath2);
if(move_uploaded_file($tmpFilePath, $newFilePath))
{
$date=date("Y-m-d");
}
}
}
$d=mysql_query("INSERT INTO properties (iname,cdate) VALUES('".$values_insert."',NOW())") or die(mysql_error());
}

Related

How to upload multiple image with array?

I have a form, How to insert in database one by one.For example :-
<form method="post">
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="file" name="img[]">
</form>
if(isset($_POST['submit'])){
if(count($_FILES['img']['name']) > 0){
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != ""){
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "uploaded/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
this may help you

multiple file upload in php not working on my server

i want to multiple file upload in php.. but its not working
here is my code. and link
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit"/>
Link
<?php
if(isset($_FILES['files']))
{
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name )
{
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$desired_dir="uploads";
if(empty($errors)==true)
{
if(is_dir($desired_dir)==false)
{
mkdir("$desired_dir", 0777);
}
if(is_dir("$desired_dir/".$file_name)==false)
{
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else
{
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
}else{
}
}
if(empty($error)){
echo "Success";
} }
?>
here is the upload code. when i am select multiple file to upload than no any response from server you can see live on my given link.
This works for me.
Make sure your uploads directory is writeable
You have to create a loop for each files
upload.php
<?php
// Count # of uploaded files in array
$total = count($_FILES['files']['name']);
// Loop through each file
for($i=0; $i<$total; $i++) {
$tmpFilePath = $_FILES['files']['tmp_name'][$i];
if ($tmpFilePath != ""){
$newFilePath = "uploads/" . $_FILES['files']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
echo 'Upload success!';
}
}
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>
Use like
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>
<?php
$target_dir = "uploads/";
if(isset($_POST))
{
if(isset($_FILES["files"]["name"]) && is_array($_FILES["files"]["name"]) && $_FILES["files"]["name"]!= false)
{
foreach($_FILES["files"]["name"] as $key=>$name)
{
$target_file = $target_dir . basename($name);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["files"]["tmp_name"][$key], $target_file)) {
echo $_FILES["files"]["name"][$key] . " uploaded <br/>";
}
}
}
} ?>
If you are uploading big files then please check your php.ini settings , check https://doc.owncloud.org/server/8.0/admin_manual/configuration_files/big_file_upload_configuration.html

File not uploading into the map

This is my html code:
<form action="producttoevoegen.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
<label for="Upload"></label>
<input type="file" name="Upload[]" multiple="multiple" id="Upload" />
<input type="submit" name="UploadButton" id="UploadButton" value="Upload" />
</form>
This is my php code:
<?php
if(isset($_FILES['Upload'])){
$UploadName = $_FILES['Upload']['name'];
$UploadType = $_FILES['Upload']['type'];
$FileSize = $_FILES['Upload']['size'];
$UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);
if(($FileSize > 125000)){
die("Error - File too Big");
}
for($i=0; $i<count($UploadName); $i++) {
$tmpFilePath = $_FILES['Upload']['tmp_name'][$i];
if ($tmpFilePath != ""){
$newFilePath = /upload/" . $UploadName[$i];
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
}
}
}
}
When I try to upload files it doesn't work. It doesn't show in the map. I've tried a lot of things but nothing worked. Does anyone see the mistake I've made? Thanks in advance!!
if(isset($_FILES['Upload'])){
for($i=0; $i<count($UploadName); $i++) {
$UploadName = $_FILES['Upload']['name'][$i];
$UploadType = $_FILES['Upload']['type'][$i];
$FileSize = $_FILES['Upload']['size'][$i];
$UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);
if(($FileSize > 125000)){
die("Error - File too Big");
}
$tmpFilePath = $_FILES['Upload']['tmp_name'][$i];
if ($tmpFilePath != "") {
$newFilePath = "/upload/" . $UploadName[$i];
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
}
}
}
}
Please find updated code
<form action="producttoevoegen.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
<label for="Upload"></label>
<input type="file" name="Upload" multiple="multiple" id="Upload" />
<input type="submit" name="UploadButton" id="UploadButton" value="Upload" />
</form>
Use this code for PHP script which is given by #Minesh Patel
if(isset($_FILES['Upload'])){
for($i=0; $i<count($UploadName); $i++) {
$UploadName = $_FILES['Upload']['name'][$i];
$UploadType = $_FILES['Upload']['type'][$i];
$FileSize = $_FILES['Upload']['size'][$i];
$UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);
if(($FileSize > 125000)){
die("Error - File too Big");
}
$tmpFilePath = $_FILES['Upload']['tmp_name'][$i];
if ($tmpFilePath != "") {
$newFilePath = "/upload/" . $UploadName[$i];
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
}
}
}
}

PHP: Upload more files

please help me with my PHP upload problem:
My code:
<?php
if(isset($_POST['uploadsubmit'])) {
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./images/" . $_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
}
?>
<form action="#" method="post" name="uploadimg">
<input type="file" name="upload[]" /><br />
<input type="file" name="upload[]" /><br /><br />
<input type="submit" name="uploadsubmit" value="Submit">
</form>
and my problem is:
Notice: Undefined index: upload in
C:\web\php_structure\type\article.php on line 71
line 71:
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
and upload is not executed.
Upload in php.ini is On
Thanks...

post multiple image using 1 field in a form

My code in here. how can I upload more then 1 image using 1 input field?
<?php
if (isset($_POST['beopen_form'])) {
if ($_FILES["file1"]["error"] > 0) {
echo "Error: " . $_FILES["file1"]["error"] . "<br>";
} else {
$x = mysql_insert_id();
$path_array = wp_upload_dir();
$old_name = $_FILES["file1"]["name"];
$split_name = explode('.', $old_name);
$time = time();
$file_name = $time . "." . $split_name[1];
$tmp_name = $_FILES["file1"]["tmp_name"];
move_uploaded_file($_FILES["file"]["tmp_name"], $path . "/" . $old_name);
$path2 = $path . "/" . $old_name;
mysql_query("INSERT INTO carimage (image,carid,created,updated) VALUES ('$path2','$x','$created','$updated') ON DUPLICATE KEY UPDATE image='$path2',description='$makeid',updated='$updated'");
}
}
?>
<form enctype="multipart/form-data" class="beopen-contact-form" id="signupForm" novalidate="novalidate" action="<?php echo get_permalink(); ?>" method="post">
<input type="file" name="file" id="file">
<div id="recaptcha_div"></div><br>
<input type="hidden" name="beopen_form" value="1" /><!-- button -->
<button class="button send-message" type="submit">
<span class="send-message"></span><?php _e('Update', 'beopen');?>
</button>
</form>
html :-
<input type="file" name="file" id="file" multiple>
PHP CODE:-
//Loop through each file
for($i=0; $i<count($_FILES['file']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['file']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
I TAKE THIS CODE FROM :-
Multiple file upload in php
Before Post any question you should search for problem....!!!

Categories