Php 上载大于2 mb的文件时出错
我有2个php文件: 第一 名称form_upload.phpPhp 上载大于2 mb的文件时出错,php,Php,我有2个php文件: 第一 名称form_upload.php <html> <head><title>File Upload</title></head> <body> <ol> <li>Enter the file name of the product picture you want to upload or the the browse button
<html>
<head><title>File Upload</title></head>
<body>
<ol>
<li>Enter the file name of the product picture you want to upload or the the browse button to navigate to the picture file</li>
<li>when the path to the picture file shows in the text field, click the upload picture</li>
</ol>
<form enctype="multipart/form-data" action="uploadFile.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="500000"/>
<input type="file" name="pix" size="60"/>
<p><input type='submit' name="Upload" value="Upload picture"/></p>
</form>
</body>
</html>
文件上传
输入要上载的产品图片的文件名,或使用“浏览”按钮导航到图片文件
当文本字段中显示图片文件的路径时,单击上载图片
第二:uploadFile.php
<?php
if(!isset($_POST['Upload']))
{
include("form_upload.php");
}
else
{
if($_FILES['pix']['tmp_name']=="none")
{
echo "file did not successfully upload. Check the file size. File must be less than 500K";
include("form_upload.php");
exit();
}
if(!preg_match("/image\/jpeg/",$_FILES['pix']['type']))
{
echo "only jpg files are allowed. Please try another file";
include("form_upload.php");
exit();
}
else
{
$destination='C:\xampp\htdocs\test\hinh\ '.$_FILES['pix']['name'];
$temp_file=$_FILES['pix']['tmp_name'];
move_uploaded_file($temp_file,$destination);
echo "<p>the file has successfully uploaded :{$_FILES['pix']['name']} {$_FILES['pix']['type']} ({$_FILES['pix']['size']}) </p>";
}
}
添加
在htaccess中
或更改此值
upload_max_filesize = 10M
post_max_size = 10M
在php.ini中
然后重新启动web服务器
10M代表10兆字节,如果($\u FILES['pix']['tmp\u name']==“none”),您可以插入另一个值,
--这与文件大小有什么关系?很可能是主机设置。。。。默认限制通常为2兆请注意,MAX\u FILE\u SIZE
设置为。。。对于应用程序客户端的用户来说,这只是一个方便的特性<代码>最大大小的PHP设置(在服务器端)不能被愚弄。
当然假设主机允许访问PHP.ini或允许htaccess覆盖
upload_max_filesize = 10M
post_max_size = 10M