简体   繁体   English

iPhone上的HTML上传(iOS):文件名始终相同(image.jpg,image.png,...)

[英]HTML Upload on iPhone (iOS): filename is always same (image.jpg, image.png, …)

I am using very simple code to upload files in my responsive website. 我使用非常简单的代码在响应式网站上传文件。 But when I upload image using iPhone , the image name is always image.jpg irrespective of actual image name. 但是当我使用iPhone上传图像时,无论实际图像名称如何,图像名称始终为image.jpg

Any workaround for this problem? 针对此问题的任何解决方法?

I created this sample page with small code for debugging purpose: 我创建了这个带有小代码的示例页面,用于调试目的:

<?php

    if ($_SERVER['REQUEST_METHOD'] === 'POST')
    {
        print "<pre>";
        echo 'post object info:';
        print_r($_FILES);
        print "</pre>";
    }

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>File Upload Test for iphone</title>
</head>
<body>
    <form enctype="multipart/form-data" method="POST">
        <input type="hidden" name="MAX_FILE_SIZE" value="512000" />
        <input name="userfile" type="file" /> <br />
        <input type="submit" value="Send File" />
    </form>
</body>
</html>

Demo: http://codepad.viper-7.com/VnTfb3/55dev ? 演示: http//codepad.viper-7.com/VnTfb3/55dev

I ran into the same problem but I was using 3 images in my upload script. 我遇到了同样的问题,但我在上传脚本中使用了3张图片。 The quickest, easiest solution for me was to add the current date and time in any format (epoch is probably the best for this) as well as a letter or combination of letters to the filename to distinguish the filename. 对我来说最快捷,最简单的解决方案是以任何格式添加当前日期和时间(纪元可能是最好的)以及文件名的字母或字母组合以区分文件名。

$date = date('U');

$filename1 = str_replace(' ', '%20', $_FILES['image1']['name']);

$target1 = 'images/';

$file1 = $_FILES['image1'];

$target1 .= $date.'A'.$file1['name'];

$fileName1 = $date.'A'.$file1['name'];

The above is some of the code I used for my script but my script is obviously much different than yours. 以上是我用于脚本的一些代码,但我的脚本显然与你的脚本大不相同。 I just pasted it to show how you can modify the name of a file when it is being processed and uploaded. 我只是粘贴它来展示如何在处理和上传文件时修改文件的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM