dongyo1818 2014-09-18 21:49
浏览 33

PHP文件上传在智能手机上不起作用

I made a simple file uploader in PHP, where the user is able to upload some pictures. The script then puts these images into a directory called 'uploads'. Another script creates a gallery with all the pictures from 'uploads', so everytime a user uploads a new picture, the file is added to the gallery.

It's working fine - but only when I use it on my computer. When I try it on iPad/iPhone, the uploaded pictures have a file size of 0 bytes, and you also can't see them in the gallery.

Here's my code:

Form:

<form action="fupload.php" method="post" enctype="multipart/form-data">
    <div class="upload-btn">
        <label class="fileContainer">
            Choose Pictures
            <input name="datei[]" type="file" accept="image/*;capture=camera"multiple />
        </label>
        <br /><input id="file" type="submit" value="Upload"></input>
    </div>
</form>

Uploader:

<?php

// Maximale Größe der Datei (Byte)
$maxSize = 20971520;
// Hilfsvariable für Array Index
$i = 0;

foreach($_FILES as $file):
  foreach($file['name'] as $filename):

     if($file['size'][$i] > $maxSize) {
          echo "<h2 class='err_message'>Dein Bild ist leider zu groß</h2>";
          ++$i;
          continue;           
      }
      // Eindeutiger Dateiname
      $save_as_name = uniqid().'_'.$filename;
      // Datei auf Server speichern
      move_uploaded_file($file['tmp_name'][$i], 'uploads/'.$save_as_name);  
      ++$i;
  endforeach;
endforeach;
echo "<img src='img/ok.svg' class='okay' /><h2 class='message'>Deine Bilder wurden erfolgreich hochgeladen</h2>";
echo $_FILES;

?>

Gallery:

<?php
 $ordner = "uploads";
 $allebilder = scandir($ordner); // Sortierung A-Z
 foreach ($allebilder as $bild) {

// Zusammentragen der Dateiinfo
$bildinfo = pathinfo($ordner."/".$bild); 

// Größe ermitteln für Ausgabe
$size = ceil(filesize($ordner."/".$bild)/20971520); 
//1024 = kb | 1048576 = MB | 1073741824 = GB

if ($bild != "." && $bild != ".."  && $bild != "_notes" && $bildinfo['basename'] != "Thumbs.db") { 
?>
<div class="img">
    <a href="<?php echo $bildinfo['dirname']."/".$bildinfo['basename'];?>">
        <img src="<?php echo $bildinfo['dirname']."/".$bildinfo['basename'];?>" width="300"  title="Thumbnail" />
    </a> 
</div>
<?php
}
}
?>

I wonder if someone could help me

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求帮我调试一下freefem代码
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图