gpt4 book ai didi

php - 如何在此代码中添加大小限制?

转载 作者:行者123 更新时间:2023-11-30 23:46:08 24 4
gpt4 key购买 nike

如何在此代码中添加大小限制?我是 php 的新手。尝试创建表单。我在网上找到了这段代码,但是当我上传一个文件时,它只接受 700kb 文件,不能超过 700kb,否则会出错。我至少需要 20mb。我必须在我的代码中写什么才能让它工作?即使它应该有助于更新。请帮忙

<body>
<div id="art-main">
<div id="art-header-bg" class="clearfix">
</div>
<div id="art-hmenu-bg" class="art-bar art-nav clearfix">
</div>
<div class="art-sheet clearfix">
<header class="art-header clearfix">
<div class="art-shapes">
<h1 class="art-headline" data-left="0.5%">
<a href="http://www.99demos.blogspot.com" target="_blank">library</a>
</h1>
<h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2>
</div>
<nav class="art-nav clearfix">
<div class="art-nav-inner">
<ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul>
</div>
</nav>
</header>
<div class="art-layout-wrapper clearfix">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content clearfix"><article class="art-post art-article">
<h2 class="art-postheader">customer form</h2>

<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%" >
<br>


<?php
ob_start();
include('include/connect.php');
if (isset($_GET['id'])) {

$qry = "SELECT * FROM tbl_emp where id=" . $_GET['id'];
$result = mysql_query($qry);
$row = mysql_fetch_array($result);

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$age = $_POST["age"];
$gender = $_POST['gender'];
$martial = $_POST["martial"];
$contact = $_POST["contact"];
$email = $_POST["email"];
$location = $_POST["location"];
$drname = $_POST["drname"];
$cname = $_POST["cname"];
$clocation = $_POST["clocation"];
$implants = implode(',', $_POST['implants']);
$problem = $_POST["problem"];
$tgiven = $_POST["tgiven"];
$tdate = $_POST["tdate"];
IF ($_FILES['file']['name'] != '') {
$file = 'uploads/' . $row['image'];
@unlink($file);
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name = time() . "." . $ext;
$fileUpload = move_uploaded_file($tmp_name, "uploads/" . $image_name);
} else {
$image_name = $row['image'];
}

$sqlAdd = "update tbl_emp set name='" . $name . "', age='" . $age . "', gender='" . $gender . "', martial='" . $martial . "', contact='" . $contact . "', email='" . $email . "', location='" . $location . "', drname='" . $drname . "', cname='" . $cname . "', clocation='" . $clocation . "', implants='" . $implants . "', problem='" . $problem . "', tgiven='" . $tgiven . "', tdate='" . $tdate . "', image='" . $image_name . "' where id=" . $_GET['id'];
mysql_query($sqlAdd);
header("Location:add.php?id=" . @$_GET['id'] . "&msg=success");
exit;
}
} else {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$age = $_POST["age"];
$gender = $_POST['gender'];
$martial = $_POST["martial"];
$contact = $_POST["contact"];
$email = $_POST["email"];
$location = $_POST["location"];
$drname = $_POST["drname"];
$cname = $_POST["cname"];
$clocation = $_POST["clocation"];
$implants = $_POST["implants"];

$problem = $_POST["problem"];
$tgiven = $_POST["tgiven"];
$tdate = $_POST["tdate"];
IF ($_FILES['file']['name'] != '') {
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name = time() . "." . $ext;

$fileUpload = move_uploaded_file($tmp_name, "uploads/" . $image_name);
}
$sqlAdd = mysql_query("insert into tbl_emp(name,age,gender,martial,contact,email,location,drname,cname,clocation,implants,problem,tgiven,tdate,image) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$drname','$cname','$clocation','$implants','$problem','$tgiven','$tdate','$image_name')");
header("Location:index.php?msg=success");
exit;
}
}
ob_end_flush();

if (isset($_GET['msg'])) {
?>
<div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
<?php
}
?>
<form method="post" name="login" id="login" enctype="multipart/form-data">
<table class="table" width="100%">
<tr>
<td width="10%">Customer Details</td>
<td></td>
</tr>
<tr>
<td width="10%">Full Name</td>
<td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name']; ?>"></td>
</tr>
<tr>
<td width="20%">Age</td>
<td><input name="age" type="text" value="<?php echo @$row['2']; ?>" ></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="Radio" name="gender" value="male" <?php
if ($gender == 'male') {
echo 'checked';
}
?> />
Male
<input type="Radio" name="gender" value="female" <?php
if ($gender == 'female') {
echo 'checked';
}
?> />
Female</td>
</tr>
<tr>
<td width="10%">Martial Status</td>
<td><input name="martial" type="text" value="<?php echo @$row['4']; ?>" ></td>
</tr>
<tr>
<td width="20%">Contact Number</td>
<td><input name="contact" type="text" value="<?php echo @$row['5']; ?>"></td>
</tr>
<tr>
<td width="10%">Email Address</td>
<td><input name="email" type="text" value="<?php echo @$row['6']; ?>"></td>
</tr>
<tr>
<td width="10%">Location</td>
<td><input name="location" type="text" value="<?php echo @$row['7']; ?>" ></td>
</tr>
<tr>
<td width="10%">Treatment Details</td>
<td></td>
</tr>
<tr>
<td width="10%">Doctor Name</td>
<td><input name="drname" type="text" value="<?php echo @$row['8']; ?>" ></td>
</tr>
<tr>
<td width="10%">Clinic Name</td>
<td><input name="cname" type="text" value="<?php echo @$row['9']; ?>" ></td>
</tr>
<tr>
<td width="10%">Clinic Location & Branch</td>
<td><input name="clocation" type="text" value="<?php echo @$row['10']; ?>" ></td>
</tr>
<tr>
<td width="10%">Implants</td>
<td>

<select name="implants" id="implants" value="<?php echo @$row['11']; ?>">
<option <?php if ($implants == '1') echo 'selected="selected'; ?> value="1">1</option>
<option <?php if ($implants == '2') echo 'selected="selected'; ?> value="2">2</option>
<option <?php if ($implants == '3') echo 'selected="selected'; ?> value="3">3</option>
</select>
</td>
</tr>
<tr>
<td width="10%">Problem</td>
<td><input name="problem" type="text" value="<?php echo @$row['12']; ?>" ></td>
</tr>
<tr>
<td width="10%">Treatment Given</td>
<td><input name="tgiven" type="text" value="<?php echo @$row['13']; ?>" ></td>
</tr>
<tr>
<td width="10%">Treatment Date</td>
<td><input name="tdate" type="date" value="<?php echo @$row['14']; ?>" ></td>
</tr>
<tr>
<td>multifile
<td>
<input id="fileupload" type="file" multiple="multiple" />
<hr />
<b>Live Preview</b>
<br />
<br />
<div id="dvPreview">
</div>
</td>

</tr>
<tr>
<td width="10%">X-Ray Image</td>
<td><input name="file" type="file" multiple="" ></td>

</tr>
<?php
if (isset($row['image'])) {
?>
<tr>
<td>&nbsp;</td>
<td><img src="uploads/<?php echo $row['image']; ?> " height="50" width="50"></td>
</tr>
<?php
}
?>
<tr>
<td>&nbsp;</td>
<td>
<input name="submit" value="Submit" type="submit" class="submit">
<input name="submit" value="Cancel" type="button" class="submit" onClick="window.location = 'index.php'">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="art-footer clearfix">
<div class="art-footer-inner">
<p>Copyright © 2016. All Rights Reserved.</p>
<p class="art-page-footer">

</p>
</div>
</footer>

</div>

我的 php.ini 文件

; This file is for CGI/FastCGI installations.
; Try copying it to php5.ini, if it doesn't work

; adjust memory limit

memory_limit = 64M

max_execution_time = 18000

; disable magic quotes for php request vars

magic_quotes_gpc = off

; disable automatic session start
; before autoload was initialized

flag session.auto_start = off

; enable resulting html compression

zlib.output_compression = on

; disable user agent verification to not break multiple image upload

suhosin.session.cryptua = off

; turn off compatibility with PHP4 when dealing with objects

zend.ze1_compatibility_mode = off

; PHP for some reason ignores this setting in system php.ini
; and disables mcrypt if this line is missing in local php.ini

extension=mcrypt.so

; Disable PHP errors, notices and warnings output in production mode to prevent exposing sensitive information.

display_errors = Off

最佳答案

上传文件时首先要检查的是 $_FILES 数组中提供的错误条件

// Check $_FILES['file']['error'] value.
switch ($_FILES['file']['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
echo 'No file sent.';
break;
case UPLOAD_ERR_PARTIAL :
echo 'Only part of the file was uploaded';
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
echo 'Exceeded filesize limit.';
break;
default:
echo 'Unknown errors.';
}

See Error messages explained in the manual

我猜您会收到超出文件大小限制消息。

如果是这种情况,您将不得不在 php.ini 文件中修改这些限制。

寻找

  • upload_max_filesize(上传文件的最大大小。)

  • max_file_uploads(允许同时上传的最大文件数。)

  • post_max_size(设置允许的post数据的最大大小。这个设置也会影响文件上传。要上传大文件,这个值必须大于upload_max_filesize。一般来说,memory_limit应该大于post_max_size。当一个整数是使用时,该值以字节为单位。也可以使用速记符号,如本常见问题解答中所述。如果发布数据的大小大于 post_max_size,则 $_POST 和 $_FILES 超全局变量为空。这可以在各种跟踪方式,例如通过将 $_GET 变量传递给处理数据的脚本,即 ,然后检查是否设置了 $_GET['processed']。)

  • memory_limit(这设置了允许脚本分配的最大内存量(以字节为单位)。这有助于防止编写不当的脚本耗尽服务器上的所有可用内存。请注意,要没有内存限制,请设置此指令为 -1。)

The manual so you can work out what values to use http://php.net/manual/en/ini.list.php

请记住它们是相关的,因此计算 post_max_filesize 的简单经验法则就是

post_max_size = (upload_max_filesize * max_file_uploads) 
+ some additional space for all other input fields

The manual http://php.net/manual/en/features.file-upload.php

关于php - 如何在此代码中添加大小限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35700494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com