上传数组

时间:2017-03-28 11:37:24

标签: php postgresql server-side

我正在将文件上传到文件夹,从那里我将文件的路径上传到数据库,所有这些都是使用PHP使用数组执行的。在上传之前,如何将上传的文件名更改为随机/唯一的名称?

PHP:

<?php

if(isset($_FILES['file_array'])){
    $name_array = $_FILES['file_array']['name'];
    $tmp_name_array = $_FILES['file_array']['tmp_name'];
    $type_array = $_FILES['file_array']['type'];
    $size_array = $_FILES['file_array']['size'];
    $error_array = $_FILES['file_array']['error'];







	
$conn_info = "host= port= dbname= user= password=";
$dbconn = pg_connect($conn_info) or die('could not connect:' . pg_last_error());
		 echo"<br/>sucessful connection";
       

for($i = 0; $i < count($tmp_name_array); $i++){
    if(move_uploaded_file($tmp_name_array[$i], "uploads/".$name_array[$i])){
        // get path
        $path = "uploads/".$name_array[$i];
        echo $name_array[$i]." upload is complete<br>";
        // Insert query 
        $query = "INSERT INTO example (path) VALUES ('".$path."') ;";
        pg_query($dbconn, $query);
    } else {
        echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
    }
}
}	
	
	echo "<br/> file uploaded to PostgreSQL";
	pg_close();

	?>

0 个答案:

没有答案