更改 PHP Echo 输出的字体大小

发布于 2024-10-21 12:18:38 字数 2819 浏览 4 评论 0原文

我一直在玩 W3Schools 的图像上传示例,但我想更改上传后显示的输出的字体大小。我尝试使用具有 id="up_finished"div 标签包围 php 代码,并制作如下 CSS 代码:

#up_finished {
    font-size: 10px;
}

我的代码是这样的:

<form>
    <center>
        <div id="upfinished">
            <?php
                $img_org_name = $_FILES["file"]["name"];
                $img_ext = "." . pathinfo($img_org_name, PATHINFO_EXTENSION);
                $img_name = generateKey() . $img_ext;
                $img_type = $_FILES["file"]["type"];
                $img_error = $_FILES["file"]["error"];
                $img_size = $_FILES["file"]["size"];
                $img_tmp = $_FILES["file"]["tmp_name"];

                if ((($img_type == "image/gif")
                    || ($img_type == "image/png")
                    || ($img_type == "image/jpeg")
                    || ($img_type == "image/tiff")
                    || ($img_type == "image/bmp")
                    || ($img_type == "image/pjpeg"))
                    && ($img_size < 4194304))
                {
                    if ($img_error > 0)
                    {
                        echo "Error: " . $img_error . "<br />";
                    } else {
                        echo "Upload: " . $img_name . "<br />";
                        // echo "Type: " . $img_type . "<br />";
                        echo "Size: " . round(($img_size / 1048576), 2) . " Mb<br />";

                        if (file_exists("img/" . $img_name))
                        {
                            echo $img_name . " already exists. ";
                        } else {
                            move_uploaded_file($img_tmp, "img/" . $img_name);
                            echo "Stored in: " . "img/" . $img_name;
                        }
                    }
                } else {
                    echo "Error! Try re-submiting the image <br />
                         Error ID: " . $img_error . "<br />";
                }

                function generateKey()
                {
                    $chars = "abcdefghijkmnopqrstuvwxyz023456789"; 
                    srand((double)microtime()*1000000); 
                    $i = 0; 
                    $pass = '' ; 

                    while ($i <= 3)
                    { 
                        $num = rand() % 33; 
                        $tmp = substr($chars, $num, 1); 
                        $pass = $pass . $tmp; 
                        $i++; 
                    } 
                    return $pass;
                }
            ?>
        </div>
    </center>
</form>

但什么也没有发生了。我应该怎么办?

I have been playing around with the image upload example from W3Schools, but I want to change the font size of the output that appears after the upload. I've tried surrounding the php code with a div tag that has the id="up_finished" and made a CSS code like this:

#up_finished {
    font-size: 10px;
}

My code is like this:

<form>
    <center>
        <div id="upfinished">
            <?php
                $img_org_name = $_FILES["file"]["name"];
                $img_ext = "." . pathinfo($img_org_name, PATHINFO_EXTENSION);
                $img_name = generateKey() . $img_ext;
                $img_type = $_FILES["file"]["type"];
                $img_error = $_FILES["file"]["error"];
                $img_size = $_FILES["file"]["size"];
                $img_tmp = $_FILES["file"]["tmp_name"];

                if ((($img_type == "image/gif")
                    || ($img_type == "image/png")
                    || ($img_type == "image/jpeg")
                    || ($img_type == "image/tiff")
                    || ($img_type == "image/bmp")
                    || ($img_type == "image/pjpeg"))
                    && ($img_size < 4194304))
                {
                    if ($img_error > 0)
                    {
                        echo "Error: " . $img_error . "<br />";
                    } else {
                        echo "Upload: " . $img_name . "<br />";
                        // echo "Type: " . $img_type . "<br />";
                        echo "Size: " . round(($img_size / 1048576), 2) . " Mb<br />";

                        if (file_exists("img/" . $img_name))
                        {
                            echo $img_name . " already exists. ";
                        } else {
                            move_uploaded_file($img_tmp, "img/" . $img_name);
                            echo "Stored in: " . "img/" . $img_name;
                        }
                    }
                } else {
                    echo "Error! Try re-submiting the image <br />
                         Error ID: " . $img_error . "<br />";
                }

                function generateKey()
                {
                    $chars = "abcdefghijkmnopqrstuvwxyz023456789"; 
                    srand((double)microtime()*1000000); 
                    $i = 0; 
                    $pass = '' ; 

                    while ($i <= 3)
                    { 
                        $num = rand() % 33; 
                        $tmp = substr($chars, $num, 1); 
                        $pass = $pass . $tmp; 
                        $i++; 
                    } 
                    return $pass;
                }
            ?>
        </div>
    </center>
</form>

But nothing happened. What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我也只是我 2024-10-28 12:18:38

@Nathan Campos:如果以下代码示例也不起作用,则其他内容可能会覆盖您的字体大小;另一个样式表设置或者很可能是浏览器设置。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>questions/5285643</title>

<style type="text/css">
<!--
#up_finished {
    font-size: 10px;
}
#up_finished span {
    /* for demonstration purposes */
    font-size: 16px;
}
// -->
</style>
</head>

<body>

<form>
    <center>
        <div id="up_finished">
            <?php
            /* Replace this with your PHP code */
            ?>
            <br />Filler text which should be
            10px large<br />
            <span>Filler text which should be
            16px large</span>
        </div>
    </center>
</form>

</body>
</html>

jsFiddle: http://jsfiddle.net/phF9b/ 查看正在运行的代码。

@Nathan Campos: If the following code sample also doesn't work, something else might be overriding your font size; either another stylesheet setting or quite possible, a browser setting.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>questions/5285643</title>

<style type="text/css">
<!--
#up_finished {
    font-size: 10px;
}
#up_finished span {
    /* for demonstration purposes */
    font-size: 16px;
}
// -->
</style>
</head>

<body>

<form>
    <center>
        <div id="up_finished">
            <?php
            /* Replace this with your PHP code */
            ?>
            <br />Filler text which should be
            10px large<br />
            <span>Filler text which should be
            16px large</span>
        </div>
    </center>
</form>

</body>
</html>

jsFiddle: http://jsfiddle.net/phF9b/ to see the code in action.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文