简体   繁体   中英

iPhone file upload from browser fails to white screen

Has anybody experienced/overcome problems with uploading files via browser on iPhone?

I have a simple form that takes name, email, and a photo attachment, sending them through PHP's mail function on submission, and it works just fine on Android and on desktop browsers.

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

However, on iPhone, when you choose a photo from the camera roll, it simply brings you to a blank white screen, leaving you only the option to go back / start over.

There was a documented bug in the first release iOS8 where Safari wasn't supporting file uploads, but this is happening on multiple browsers and that bug was fixed a few months ago.

Any help is appreciated. 在此处输入图片说明

Edit: Including my PHP code, although I don't think that it is what is causing the problem as I can't even get to the point where I submit/call this file.

<?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
    }

Your HTML codes contain logic errors.

Any button tag without type="button" will be considered as a Submit button, which acts the same as the following:

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

Thus, to solve your problem, you should add type="button" in your photo buttons (at least 2 buttons I spotted).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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