iPhone上的HTML上传(iOS):文件名始终相同(image.jpg,image.png,...) [英] HTML Upload on iPhone (iOS): filename is always same (image.jpg, image.png, ...)

查看:1126
本文介绍了iPhone上的HTML上传(iOS):文件名始终相同(image.jpg,image.png,...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用非常简单的代码在我的响应式网站上传文件。但是当我使用 iPhone 上传图片时,图片名称始终是 image.jpg ,与图片名称无关。

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.

这个问题的解决方法是什么?

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>

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

推荐答案

我遇到了同样的问题,但我在上传脚本中使用了3张图片。对我来说,最快捷,最简单的解决方案是以任何格式添加当前的日期和时间(时代可能是最好的),以及一个字母或字母的组合来区分文件名。

I ran into the same problem but I was using 3 images in my upload script. 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.

这篇关于iPhone上的HTML上传(iOS):文件名始终相同(image.jpg,image.png,...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆