Php 获取文件在$\u FILES数组中的位置号

Php 获取文件在$\u FILES数组中的位置号,php,Php,我有一个带有预览功能的图像管理器,我需要知道图像在$\u文件数组中的位置号,这样我就可以知道我必须删除哪一个并上载新的图像。图像名称只是数字(即1.jpg、2.jpg等) 例如,我在预览中有6个图像(6个输入),我需要替换其中一些图像,因此我单击要替换的图像的“移除”按钮,然后拖放新图像。单击“上载”时,我需要知道图像填充了多少输入,以及它们在$\u文件数组中的位置,以便我不会删除错误的输入 如果其中一个预览被删除且未被替换,我必须从服务器中删除该文件,我正在考虑使用值为0/1的隐藏输入来确定用

我有一个带有预览功能的图像管理器,我需要知道图像在
$\u文件
数组中的位置号,这样我就可以知道我必须删除哪一个并上载新的图像。图像名称只是数字(即1.jpg、2.jpg等)

例如,我在预览中有6个图像(6个输入),我需要替换其中一些图像,因此我单击要替换的图像的“移除”按钮,然后拖放新图像。单击“上载”时,我需要知道图像填充了多少输入,以及它们在
$\u文件
数组中的位置,以便我不会删除错误的输入

如果其中一个预览被删除且未被替换,我必须从服务器中删除该文件,我正在考虑使用值为0/1的隐藏输入来确定用户是否要删除图像,这些值由“删除图像”按钮设置(每个输入都有自己的值)。我在思考如何完成这件事时遇到了一些困难

这是我已经拥有的:

$file_count = count($_FILES['file']['tmp_name']);
$id = isset($_GET['id']) && $_GET['id'] != '' ? (int) $_GET['id'] : 0;

if ($id !== 0) {

    $path = realpath('/home/aet/websites/images/property/' . $id . '/');

    if ( FALSE !== $path && is_dir($path) ) {

        $url = [];

        for($i = 0; $i < $file_count; $i++) {

            if ($_FILES['file']['name'][$i] != '') {

                $path = $path . (++$i) . '.jpg';

                if (file_exists($path)) unlink($path);

                if (move_uploaded_file($file_count[$i], $path)) {

                    $url[] = 'http://static.website.com/images/property/' . $id . '/' . (++$i) . '.jpg';

                } else die('Error uploading image (' . (++$i) . ')' );
            } else {

                // first we have to check if the user requested the file deletion
                // (no image preview in the html)
                //unlink($path);

            }
        }

        if ( !empty($url) ) {
            $mysqli = $staff->aet->getAetSql();
            $mysqli->set_charset('utf8');

            $mysqli->autocommit(FALSE);
            $value = NULL;

            if ($stmt = $mysqli->prepare('INSERT INTO img (path, property) VALUES (?, ?)')) {

                $stmt->bind_param('si', $value, $id);

                foreach ($url as $key => $value) {
                    $stmt->execute();
                }

                if ( $mysqli->commit() ) {
                    header('Location: /property');
                } else die('DB Error.');
            }
        }
    } else die('Error (path does not exist)');
}
$file\u count=count($\u FILES['file']['tmp\u name']);
$id=isset($\u GET['id'])&&&$\u GET['id']!=''?(int)$_GET['id']:0;
如果($id!==0){
$path=realpath('/home/aet/websites/images/property/'.$id'/');
if(FALSE!=$path&&is_dir($path)){
$url=[];
对于($i=0;$i<$file\u count;$i++){
如果($_FILES['file']['name'][$i]!=''){
$path=$path.(++$i)。'.jpg';
如果(文件_存在($path))取消链接($path);
如果(移动上传的文件($file\u count[$i],$path)){
$url[]='http://static.website.com/images/property/“.$id./”(++$i)。“.jpg”;
}else die('上传图像时出错('.(++$i)。');
}否则{
//首先,我们必须检查用户是否请求删除文件
//(html中没有图像预览)
//取消链接($path);
}
}
如果(!空($url)){
$mysqli=$staff->aet->getAetSql();
$mysqli->set_字符集('utf8');
$mysqli->autocommit(FALSE);
$value=NULL;
if($stmt=$mysqli->prepare('INSERT-INTO-img(路径、属性)值(?,))){
$stmt->bind_参数('si',$value,$id);
foreach($url作为$key=>$value){
$stmt->execute();
}
如果($mysqli->commit()){
标题('Location:/property');
}否则会死亡(“数据库错误”);
}
}
}else die('错误(路径不存在)');
}

是否只使用数组键
$i
在您的
for
循环中,在这种情况下,嗯,是的,我想我需要休息一下:P