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>
Demo: http://codepad.viper-7.com/VnTfb3/55dev?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With