简体   繁体   English

从移动设备上传图像文件

[英]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. 简单的上传脚本(允许工作人员更改个人资料图片)可以在PC上正常工作,但是当我尝试从iPhone上传照片时,页面就像在试图加载一样停止了,什么也没发生。

This is my entire test PHP file: 这是我的整个测试PHP文件:

<?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. 再次,这在PC上可以正常工作,但是当我从iPhone触摸“上传”时,它就挂起了。 If I remove the name="uploadedFile", the page executes, but of course there is no file there. 如果删除name =“ uploadedFile”,则页面将执行,但是当然那里没有文件。 How can I get this to recognize an image from an iPhone? 我怎样才能识别来自iPhone的图像?

Do you, by any chance, do anything with the image after upload that includes GD? 上传后包含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. 如果人像效果很好,但风景引起挂起(或其他原因,无法记住),则EXIF数据可能存在问题,表明图像已旋转,但GD无法正确处理。

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. 解决方案在于获取EXIF数据(使用exif_read_data()),然后使用imagemagick(调用中的-strip param)将其剥离,然后使用GD或image magick旋转图像,这将为您留下可操作的图像而不会产生错误。

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>

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. 我在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. 但是,当我在Windows Server 2008 R2,XAMPP,PHP 5.6.15上放置相同的代码时,它可以正常工作。 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. 当我找出原因时,我将发布最终结果,我怀疑是与IIS 7有关。

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

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