【问题标题】:iPhone file upload from browser fails to white screen从浏览器上传 iPhone 文件失败到白屏
【发布时间】:2015-03-13 02:59:03
【问题描述】:

有没有人遇到/克服通过 iPhone 上的浏览​​器上传文件的问题?

我有一个简单的表单,它包含姓名、电子邮件和照片附件,在提交时通过 PHP 的邮件功能发送它们,它在 Android 和桌面浏览器上运行良好。

<input id="selectPhotoInput" type="file" name="uploaded_file"  accept="image/*">  

但是,在 iPhone 上,当您从相机胶卷中选择一张照片时,它只会将您带到一个空白屏幕,您只能选择返回/重新开始。

在 iOS8 的第一个版本中有一个记录在案的错误,其中 Safari 不支持文件上传,但这发生在多个浏览器上,并且该错误已在几个月前得到修复。

感谢任何帮助。

编辑:包括我的 PHP 代码,虽然我不认为这是导致问题的原因,因为我什至无法到达提交/调用此文件的地步。

<?php 
// Pear library includes
// You should have the pear lib installed
include_once('Mail.php');
include_once('Mail/mime.php');

//Settings 
$max_allowed_file_size = 3000; // size in KB 
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
$upload_folder = './uploads/'; //<-- this folder must be writeable by the script
$your_email = 'redacted';//

$errors ='';

if(isset($_POST['submit']))
{
    //Get the uploaded file information
    $name_of_uploaded_file =  basename($_FILES['uploaded_file']['name'].$name);

    //get the file extension of the file
    $type_of_uploaded_file = substr($name_of_uploaded_file, 
                            strrpos($name_of_uploaded_file, '.') + 1);


    $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;



    ///------------Do Validations-------------
    if(empty($_POST['name'])||empty($_POST['email']))
    {
        $errors .= "\n Name and Email are required fields. ";   
    }
    if(IsInjected($visitor_email))
    {
        $errors .= "\n Bad email value!";
    }

    if($size_of_uploaded_file > $max_allowed_file_size ) 
    {
        $errors .= "\n Size of file should be less than $max_allowed_file_size";
    }
    //------ Validate the file extension -----
    $allowed_ext = false;
    for($i=0; $i<sizeof($allowed_extensions); $i++) 
    { 
        if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
        {
            $allowed_ext = true;        
        }
    }

    if(!$allowed_ext)
    {
        $errors .= "\n The uploaded file is not supported file type. ".
        " Only the following file types are supported: ".implode(',',$allowed_extensions);
    }
    //send the email 
    if(empty($errors))
    {
        //copy the temp. uploaded file to uploads folder
        $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
        $tmp_path = $_FILES["uploaded_file"]["tmp_name"];

        if(is_uploaded_file($tmp_path))
        {
            if(!copy($tmp_path,$path_of_uploaded_file))
            {
                $errors .= '\n error while copying the uploaded file';
            }
        }

        //send the email
        $name = $_POST['name'];
        $visitor_email = $_POST['email'];
        $phone = $_POST['phone'];
        $user_message = $_POST['message'];
        $to = "redacted@gmail.com";
        $subject="TicketSharks: Fresh blood! ($name)";
        $from = $your_email;
        $text = "$user_message";

        $msg_body = "Name: " . $name ."<br>";
        $msg_body .= "Phone: " . $phone ."<br>";  
        $msg_body .= "Email: " . $visitor_email ."<br>";  
        $msg_body .= "Message: " . $text ."<br>";  

        $message = new Mail_mime(); 
        $message->setTXTBody($msg_body); 
        $message->addAttachment($path_of_uploaded_file);
        $body = $message->get();
        $extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
        $headers = $message->headers($extraheaders);
        header('Location: thank-you.html');
        $mail = Mail::factory("mail");
        $mail->send($to, $headers, $body);
        //redirect to 'thank-you page
    }

【问题讨论】:

  • 这取决于您如何编写上传 PHP 脚本。显示您的代码。您是否启用了错误报告和显示错误?
  • 是的。 PHP 端的上传不是问题——它甚至不能选择要上传的文件。在您提交/上传之前它会变为空白。
  • 我刚查了。在 iOS 8.2 Mobile Safari 中使用 &lt;input type="file"&gt; 可以上传文件。

标签: php iphone html file-upload camera-roll


【解决方案1】:

您的 HTML 代码包含逻辑错误。

任何不带type="button"的按钮标签都将被视为提交按钮,其作用与以下相同:

<input type="submit" value="Submit" />

因此,为了解决您的问题,您应该在照片按钮中添加type="button"(我发现至少有 2 个按钮)。

<button id="choosePhoto" type="button">Take photo</button>

【讨论】:

  • 给我发一个btc地址。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多