ipad的safari或chrome都是这样的问题。
html</code><code><!--表单-->
<div id="upload">
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</div>
php</code><code>// upload_file.php
<?php
error_reporting(E_ERROR| E_PARSE);
session_start();
$name=$_SESSION["free_print_name"];
$phone=$_SESSION["free_print_phone"];
if (!file_exists("/var/www/upload_files/".$phone)) {
mkdir("/var/www/upload_files/".$phone);
}
$DIR="/var/www/upload_files/".$phone."/";
$temp_array=explode('.', $_FILES["file"]["name"]);
$postfix=$temp_array[count($temp_array)-1];
if (
($postfix=="pdf"
|| $postfix == "doc"
|| $postfix == "docx"
|| $postfix == "rtf"
|| $postfix == "ppt"
|| $postfix == "jpg"
|| $postfix == "jpeg"
|| $postfix == "png"
|| $postfix == "psd")
&& ($_FILES["file"]["size"] < 20000000)) {
if ($_FILES["file"]["error"] > 0) {
// echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists($DIR . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
header('Location: http://59.78.7.9/index.html');
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], $DIR. $_FILES["file"]["name"]);
echo "Stored in: " . $DIR . $_FILES["file"]["name"];
header('Location: http://59.78.7.9/index.html');
}
}
} else {
echo "Invalid file, you can't upload files of ".$postfix;
}
?>
ipad的safari或chrome都是这样的问题。
html</code><code><!--表单-->
<div id="upload">
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</div>
php</code><code>// upload_file.php
<?php
error_reporting(E_ERROR| E_PARSE);
session_start();
$name=$_SESSION["free_print_name"];
$phone=$_SESSION["free_print_phone"];
if (!file_exists("/var/www/upload_files/".$phone)) {
mkdir("/var/www/upload_files/".$phone);
}
$DIR="/var/www/upload_files/".$phone."/";
$temp_array=explode('.', $_FILES["file"]["name"]);
$postfix=$temp_array[count($temp_array)-1];
if (
($postfix=="pdf"
|| $postfix == "doc"
|| $postfix == "docx"
|| $postfix == "rtf"
|| $postfix == "ppt"
|| $postfix == "jpg"
|| $postfix == "jpeg"
|| $postfix == "png"
|| $postfix == "psd")
&& ($_FILES["file"]["size"] < 20000000)) {
if ($_FILES["file"]["error"] > 0) {
// echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists($DIR . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
header('Location: http://59.78.7.9/index.html');
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], $DIR. $_FILES["file"]["name"]);
echo "Stored in: " . $DIR . $_FILES["file"]["name"];
header('Location: http://59.78.7.9/index.html');
}
}
} else {
echo "Invalid file, you can't upload files of ".$postfix;
}
?>
exif_imagetype()函数检查实际文件头。
请问这个问题怎么解决的?我是苹果手机上传图片名称默认就改成了image.jpg. 我们用的是HTML5.安卓和浏览器上传都正常。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号