使用PHP表单在FTP上上传多个图像

时间:2018-11-20 19:58:49

标签: php

我正在尝试使用PHP表单将多个图像上传到我的FTP服务器。

我有用于将照片存储在服务器(/domains/mydomain.com/public_html/static/img/storage/location)上的文件夹。

当前代码无缘无故不想将图像上传到我的服务器。我在哪里弄错了?我也想从该图像获取url,例如:https://example.com/static/img/storage/location/imagename.jpg字符串中的$image_1

HTML

<form method='POST' enctype='multipart/form-data'>
  <input type='file' name='image[]' class='upload' accept='image/*' multiple/>
</form>

PHP

  $image = $_POST['image'];

  // uploading images to storage folder
  $target = './static/img/storage/location/';
  $count = 0;
  foreach ($_FILES['image']['name'] as $filename) {
    $tmp = $_FILES['image']['tmp_name'][$count];
    $count = $count + 1;
    $temp = $target.basename($filename);
    move_uploaded_file($tmp, $temp);
    $temp = '';
    $tmp = '';
  }
  $image_0 = $_FILES['image']['name'][0];
  $image_1 = $_FILES['image']['name'][1];
  $image_2 = $_FILES['image']['name'][2];
  $image_3 = $_FILES['image']['name'][3];
  $image_4 = $_FILES['image']['name'][4];

  $db->Query("INSERT INTO user_image (image_0, image_1, image_2, image_3, image_4) VALUES ('$image_0', '$image_1', '$image_2', '$image_3', '$image_4')");

0 个答案:

没有答案