我的代码来自:http://techstream.org/Web-Development/PHP/Multiple-File-Upload-with-PHP-and-MySQL
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];
}
我需要为每个图像创建会话,例如:
$_SESSION['cropped_image1'] , $_SESSION['cropped_image2'] , $_SESSION['cropped_image3'] , ...
有时我需要用户1图片上传,有时甚至更多 我想将此会话图像发送到另一个php文件。
任何帮助? 最好的问候。
答案 0 :(得分:1)
你应该使用somesort的for / foreach循环:
$i = 0
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];
$_SESSION['cropped_image_'.$i] = "your data";
$i++
}
或者你可以创建一个会话数组
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];
$_SESSION['cropped_image'][] = "your data";
}
第一个将数据存储在每个循环的单独会话中。 第二个将它全部存储在1个会话中,您可以这样访问:
$_SESSION['cropped_image'][index];