如何设置文件大小?

有这个消息 “大小上限为 2 MB”

如何在此操作上插入大小验证? 我将制作 2 个上传文件,所以这是我的代码...

.container,.container-fluid,.container-lg,.container-md,.container-sm,.container-xl,.container-xxl {
    width: 100%;
    padding-right: var(--bs-gutter-x,.75rem);
    padding-left: var(--bs-gutter-x,.75rem);
    margin-right: auto;
    margin-left: auto;

感谢您的帮助

liutihj456 回答:如何设置文件大小?

if (!isset($_GET['id'])) {

        $klasör = "../uploads/post/image";
        $inputname= $_FILES['resim'];
        $tmp_name = $inputname['tmp_name'];
        $name  = $inputname['name'];
        $size  = $inputname['size'];
        $tip  = $inputname['type'];
        $uzantı = substr($name,-4,4);
        $sayı_uret1= rand(10000,50000);
        $sayı_uret2= rand(10000,50000);
        $resim_ad = $sayı_uret1.$sayı_uret2.$uzantı;
        if (strlen($name)==0) {
            echo "<script> Notiflix.Report.Failure( 'Error','Empty File Cannot Be Uploaded ','Ok',function(){ window.location.href = window.location.href;}); </script>";
            exit();
        }else if ($size> (1024*1024*3)) {
            echo "<script>Notiflix.Report.Failure( 'Error','File Size Too Large Cannot Be Uploaded ',function(){ window.location.href = window.location.href;}); </script>";   
            exit();
        }  .......
,

验证文件大小:

<form action=
             "process.php" 
      method=
             "post"
     enctype="multipart/form-data">
<label>
  Your File:
  <input type="file" name="yourfile" />
</label>
<input type="submit" value="send" />
</form>

假设您有一个 HTML 表单:

<?php
$size = $_FILES['yourfile']['size'];
$twoMB = 2*1024*1024; // two megabytes is 2*1024*1024 bytes
if ($size < $twoMB) {
    // yay file is under 2 MB
} else {
    echo 'oops you need to select a smaller file';
}
选择文件后,您将看到如下内容:
file selection wizard

请注意,如果您选择 2GB 的文件,它仍然会到达那里。

验证

然后 process.php 看起来像这样:

int s = 1;
        for (int i = 0; i < dataGridView1.Rows.Count; i++)
        {
            for (int j = s - 1; j < dataGridView1.Rows.Count - 1; j++)
            {
                if (Convert.ToInt32(dataGridView1["Stok",j].Value) < 5)
                { s = j; dataGridView1.Rows.RemoveAt(j); break; }
            }
        }
        dataGridView1.Refresh();
本文链接:https://www.f2er.com/4708.html

大家都在问