当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to get individual file link for multiple file upload

问题描述:

I did did code to upload many files. What I want to do now is to save the path for each file event when many files are uploaded at once. I am unly able to get the folder with the code at the bottom:

<?php

$valid_formats = array("jpg", "png", "gif", "zip", "docx","zip","pdf");

$max_file_size = 1024*100;

$path = "/uploads/$orderid/";

if ( ! is_dir($path)) {

mkdir($path);

}

$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){

foreach ($_FILES['content']['name'] as $f => $name) {

if ($_FILES['content']['error'][$f] == 4) {

continue;

}

if ($_FILES['content']['error'][$f] == 0) {

if ($_FILES['content']['size'][$f] > $max_file_size) {

$message[] = "$name is too large!.";

continue; // Skip large files

}

elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){

$message[] = "$name is not a valid format";

continue; // Skip invalid file formats

}

else{ // No error found! Move uploaded files

if(move_uploaded_file($_FILES["content"]["tmp_name"][$f], $path.$name))

$count++; // Number of successfully uploaded file

}

}

}

echo "<div>You have uploaded : ". $count."</div>";

}

$sql="INSERT INTO oz2ts_web_intake_files_folder (file_id, f_folder)

VALUES

('$orderid', '$path')";

?>

网友答案:

See accepted answer of HTML 5 multi file upload with PHP

For you, your foreach loop would look like:

foreach ($_FILES['content'] as $file) { 

From here you can treat $file as it was single file (for example, to get it's name use $file['name'])

分享给朋友:
您可能感兴趣的文章:
随机阅读: