Rich701
Rich701

Reputation: 311

upload image file from mobile device

Simple upload script (to allow staff members to change their profile pic), works fine from a PC, but when I try and upload a photo from an iPhone, the page just halts, like it's trying to load, and nothing happens.

This is my entire test PHP file:

<?php
if (isset($_POST['submitNewImage'])) {
    echo 'it works, and the filename is ' . $_FILES['uploadedFile']['name'];    
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<br /><br /><br />
<form action="test.php" method="post" enctype="multipart/form-data">
<input type="file" accept="image/*" capture name="uploadedFile" /><br /><br /><br />
<input type="submit" name="submitNewImage" value="Upload" />
</form>
</body>
</html>

Again, this works fine from a PC, but when I touch "Upload" from an iPhone, it just hangs. If I remove the name="uploadedFile", the page executes, but of course there is no file there. How can I get this to recognize an image from an iPhone?

Upvotes: 0

Views: 6211

Answers (3)

Rich701
Rich701

Reputation: 311

Well, it wasn't the code, it's an issue with server the site is on. I have this on a Windows 2008 R2, IIS 7, PHP 5.6. But when I put the same code on a Windows server, 2008 R2, XAMPP, PHP 5.6.15, it works fine. Thank you all for the help, it put me in the right direction. I will post the final result when I figure out the cause, I suspect it's with IIS 7.

Upvotes: 0

Nemanja K.
Nemanja K.

Reputation: 131

Do you, by any chance, do anything with the image after upload that includes GD?

If you do - is there a difference when you try to upload portrait or landscape image? If portrait works fine, but landscape causes hang (or other way around, cannot remember), problem might be in EXIF data that suggests that image is rotated but GD cannot handle this properly.

Solution lies in getting EXIF data (with exif_read_data()), then stripping it with imagemagick (-strip param in call), following rotating image with either GD or image magick, which will leave you with image that can be manipulated without producing error.

Upvotes: 1

Saulo M
Saulo M

Reputation: 328

It works for me and it's worth a try!

<?php

    if(isset($_POST['submit_image'])) {

    $new_image = $_FILES['new_image']['name'];
    $new_image_temp = $_FILES['new_image']['tmp_name'];

    move_uploaded_file($new_image_temp, "../img/$new_image");    

    }

?>

<form action="" method="post" enctype="multipart/form-data">

    <label for="new_image">Image: </label>
    <input type="file" name="new_image">
    <input type="submit" name="submit_image" value="Submit">

</form>

Upvotes: 0

Related Questions