[mysql]在字符串转换和不支持的操作数类型在 PHP 通知︰ 数组

标签: html5 MySQL PHP
发布时间: 2016/10/24 4:49:10
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我似乎无法弄清楚。我写了一个 PHP 脚本和数组字符串转换为保持进来......在第 7 行不支持的操作数类型中......第 14 行出错时试图上载多个文件的通知。

HTML 代码︰

<form class="form-horizontal" action="uploadgambar.php" method="post" enctype="multipart/form-data" multiple>

<div class="form-group form-group-md">
  <label class="col-sm-2 control-label" for="sm">Username</label>
  <div class="col-sm-4">
    <input class="form-control" type="text" name="username" id="sm" value="<?php echo $_SESSION['username']; ?>" readonly>
  </div>
</div>

<div class="form-group form-group-md">
  <label class="col-sm-2 control-label" for="sm">Nama Gambar/Foto</label>
  <div class="col-sm-4">
    <input class="form-control" type="text" name="nama" id="sm" placeholder="Nama Gambar/Foto" required>
  </div>
</div>

<div class="form-group form-group-md">
  <label class="col-sm-2 control-label" for="sm">File</label>
  <div class="col-sm-4">
    <input class="form-control" type="file" name="file[]" id="sm" placeholder="Keterangan" multiple="multiple" required>
  </div>
</div>

PHP 代码︰

$nama = $_POST['nama'];
$username = $_POST['username'];
$file = rand(1000,100000)."-".$_FILES['file']['name'];  <- Line 7
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="../admin/gambar/";
$new_size = $file_size/1024; <- Line 14

谢谢你。

解决方法 1:

$nama = $_POST['nama'];
$username = $_POST['username'];
foreach ($_FILES['file']['name'] as $name){

   $file = rand(1000,100000)."-".$name;  
   $file_loc = $_FILES['file']['tmp_name'];
   $file_size = $_FILES['file']['size'];
   $file_type = $_FILES['file']['type'];
   $folder="../admin/gambar/";
  $new_size = $file_size/1024; 

}
赞助商