php调用多个html文件,如何使用HTTP POST选择和上传HTML和PHP多个文件?

i have created a php function which is used to upload multiple images,

this function can upload multiple images in specific folder as well it can saves the records into the database

in the following code

$arrayimage is the array of images which is sent through form

note that it will not allow upload to use multiple but you need to create different input field with same name as will you can set dynamic add field of file unput on button click.

$dir is the directory in which you want to save the image

$fields is the name of the field which you want to store in the database

database field must be in array formate

example

if you have database imagestore and fields name like id,name,address then you need to post data like

$fields=array("id"=$_POST['idfieldname'], "name"=$_POST['namefield'],"address"=$_POST['addressfield']);

and then pass that field into function $fields

$table is the name of the table in which you want to store the data..

function multipleImageUpload($arrayimage,$dir,$fields,$table)

{

//extracting extension of uploaded file

$allowedExts = array("gif", "jpeg", "jpg", "png");

$temp = explode(".", $arrayimage["name"]);

$extension = end($temp);

//validating image

if ((($arrayimage["type"] == "image/gif")

|| ($arrayimage["type"] == "image/jpeg")

|| ($arrayimage["type"] == "image/jpg")

|| ($arrayimage["type"] == "image/pjpeg")

|| ($arrayimage["type"] == "image/x-png")

|| ($arrayimage["type"] == "image/png"))

//check image size

&& ($arrayimage["size"] < 20000000)

//check iamge extension in above created extension array

&& in_array($extension, $allowedExts))

{

if ($arrayimage["error"] > 0)

{

echo "Error: " . $arrayimage["error"] . "
";

}

else

{

echo "Upload: " . $arrayimage["name"] . "
";

echo "Type: " . $arrayimage["type"] . "
";

echo "Size: " . ($arrayimage["size"] / 1024) . " kB
";

echo "Stored in: ".$arrayimage['tmp_name']."
";

//check if file is exist in folder of not

if (file_exists($dir."/".$arrayimage["name"]))

{

echo $arrayimage['name'] . " already exists. ";

}

else

{

//extracting database fields and value

foreach($fields as $key=>$val)

{

$f[]=$key;

$v[]=$val;

$fi=implode(",",$f);

$value=implode("','",$v);

}

//dynamic sql for inserting data into any table

$sql="INSERT INTO " . $table ."(".$fi.") VALUES ('".$value."')";

//echo $sql;

$imginsquery=mysql_query($sql);

move_uploaded_file($arrayimage["tmp_name"],$dir."/".$arrayimage['name']);

echo "
Stored in: " .$dir ."/ Folder
";

}

}

}

//if file not match with extension

else

{

echo "Invalid file";

}

}

//function imageUpload ends here

}

//imageFunctions class ends here

you can try this code for inserting multiple images with its extension this function is created for checking image files you can replace the extension list for perticular files in the code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值