溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

批量上傳圖片

發(fā)布時(shí)間:2020-07-15 15:27:16 來源:網(wǎng)絡(luò) 閱讀:352 作者:夢(mèng)朝思夕 欄目:web開發(fā)


前端:

<html>
<body>

<form action="/static/uploadList/upload.php" method="post"
enctype="multipart/form-data">
<label for="file">licenseImage:</label>
<input type="file" name="licenseImage[]" id="file1" /> 
<input type="file" name="licenseImage[]" id="file2" /> 
<input type="file" name="licenseImage[]" id="file3" /> 
<input type="file" name="licenseImage[]" id="file4" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

后端:

<?php
$ret = array ();
foreach ($_FILES["licenseImage"]["error"] as $key => $error) {
	if ($error > 0) {
		var_dump($_FILES['licenseImage']);
		var_dump("圖片上傳失敗!!!");
		exit;
		$ret ['status'] = 2;
		$ret ['dataInfo'] = "圖片上傳失敗!!!";
		return $ret;
	} else {
		// 臨時(shí)文件
		$pathFile = @$_FILES ['licenseImage'] ['tmp_name'][$key];
		// 文件名
		$fileName = $_FILES ["licenseImage"] ["name"][$key];

		//文件大小
		$fileSize = $_FILES["licenseImage"]["size"][$key];

		// 文件類型
		// 獲取上傳文件的擴(kuò)展名
		$extend =  strrpos($fileName,'.');//strrchr ( $fileName, '.' );
		// 文件內(nèi)容:file_get_contents($pathFile)
		// 文件大小:$_FILES["file"]["size"]
		// 文件在服務(wù)器中的暫存位置:$_FILES["file"]["tmp_name"]

		// 判斷文件類型是否是p_w_picpath
		# 當(dāng)前支持的類型列表
		$type_list = array(
                '1' => 'jpg',
                '2' => 'png',
                '3' => 'jpeg',
		);
		/*if (in_array($extend, array_values($type_list))) {
		 $ret ['status'] = 3;
		 $ret ['dataInfo'] = "上傳文件的類型錯(cuò)誤!!!";
		 return $ret;
		 }
		 #判斷上傳圖片的大小
		 if( ($fileSize/1024 ) > 2048 ){
		 $ret ['status'] = 4;
		 $ret ['dataInfo'] = "上傳已經(jīng)大于2M!!!";
		 return $ret;
		 }*/
	}//IF_END
	// 無后綴的文件名
	$fname = basename ( $fileName, $extend );
	$time = date ( "y-m-d-H-i-s" ); // 去當(dāng)前上傳的時(shí)間
	// 保存的文件名
	$fNewname = $fname . "_" . $time .".".$extend;
	$result = move_uploaded_file ( $pathFile, $fNewname );

}


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI