ホームページ > バックエンド開発 > PHPチュートリアル > PHP フォト アルバム機能の実装には、PHP 画像のアップロード、バックグラウンド管理、閲覧と削除のチュートリアルの例が含まれます

PHP フォト アルバム機能の実装には、PHP 画像のアップロード、バックグラウンド管理、閲覧と削除のチュートリアルの例が含まれます

WBOY
リリース: 2016-07-30 13:31:31
オリジナル
1494 人が閲覧しました

フォト アルバム機能の実装 (PHP 画像のアップロード、背景管理、閲覧、削除を含む) チュートリアルの例には、次の 5 つの部分が含まれています。

<html>
<head>
    <meta charset="utf-8">
    <title>相册首页</title>
    <style><span>        body{
            width</span>:<span>800px;
            margin</span>:0<span> auto;
            test</span>-align:<span>center;
        }
    </span></style>
</head>
<body>
    <h1>The simple photo album.</h1>
    <center>
    <?<span>php
    </span><span>error_reporting</span>(0<span>);
    </span><span>if</span>(!<span>$_GET</span>["page"<span>]){
        </span><span>$page</span> = 1<span>;
    }</span><span>else</span><span>$page</span> = <span>$_GET</span>["page"<span>];
        </span><span>$filename</span> = "data.dat"<span>;
        </span><span>$myfile</span> = <span>file</span>(<span>$filename</span><span>);
        </span><span>$z</span> = <span>$myfile</span>[0<span>];
        </span><span>if</span>(<span>$z</span> == <span>NULL</span><span>){
            </span><span>echo</span> "目前记录条数为:0"<span>;
        }</span><span>else</span><span>{
            </span><span>$temp</span> = <span>explode</span>("||",<span>$myfile</span>[0<span>]);
            </span><span>echo</span> "共有".<span>$temp</span>[0]."条内容"<span>;
            </span><span>echo</span> "    "<span>;
            </span><span>$p_count</span> = <span>ceil</span>(<span>$temp</span>[0]/8<span>);
            </span><span>echo</span> "分".<span>$_count</span>."页显示"<span>;
            </span><span>echo</span> "    "<span>;
            </span><span>echo</span> "当前显示第".<span>$page</span>."页"<span>;
            </span><span>echo</span> "    "<span>;
            </span><span>echo</span> "<br>"<span>;
            </span><span>if</span>(<span>$page</span> != <span>ceil</span>(<span>$temp</span>[0]/8<span>)){
                </span><span>$current_size</span> = 8<span>;
            }</span><span>else</span><span>{
                </span><span>$current_size</span> = <span>$temp</span>[0]%8<span>;
            }
            </span><span>if</span>(<span>$current_size</span> == 0<span>){
                </span><span>$current_size</span> = 8<span>;
            }
            </span><span>for</span>(<span>$i</span>=0;<span>$i</span><<span>ceil</span>(<span>$current_size</span>/4);<span>$i</span>++<span>){
                </span><span>for</span>(<span>$j</span>=0;<span>$j</span><4;<span>$j</span>++<span>){
                    </span><span>$temp</span> = <span>explode</span>("||", <span>$myfile</span>[<span>$i</span>*4+<span>$j</span>+(<span>$page</span>-1)*8<span>]);
                    </span><span>if</span>((<span>$i</span>*4+<span>$j</span>+(<span>$page</span>-1)*8)<<span>$z</span><span>){
                        </span><span>$imgfile</span> = "./images/".<span>$temp</span>[1<span>];
                        </span><span>$flag</span> = <span>getimagesize</span>(<span>$imgfile</span><span>);
                        </span><span>echo</span> "<a href=viewimage.php?id=".<span>$temp</span>[0]."><img src=/test/images/".<span>$temp</span>[1<span>];
                        </span><span>if</span>(<span>$flag</span>[0]>180||<span>$flag</span>[1]>100<span>){
                            </span><span>echo</span> " width=180 height=".<span>ceil</span>(<span>$flag</span>[1]*180/<span>$flag</span>[0<span>]);
                        }
                        </span><span>echo</span> " border=\"0\"></a>"<span>;
                    }</span><span>else</span><span>{
                        </span><span>echo</span> ""<span>;

                    }
                }

            }
            </span><span>echo</span> "</table>"<span>;
        }
        </span><span>echo</span> "<p>"<span>;
        </span><span>$prev_page</span> = <span>$page</span> - 1<span>;
        </span><span>$next_page</span> = <span>$page</span> + 1<span>;
        </span><span>if</span>(<span>$page</span> <= 1<span>){
            </span><span>echo</span> "第一页 | "<span>;
        }</span><span>else</span><span>{
            </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=1'>第一页</a> | "<span>;
        }
        </span><span>if</span>(<span>$prev_page</span> < 1<span>){
            </span><span>echo</span> "上一页 | "<span>;
        }</span><span>else</span><span>{
            </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=<span>$prev_page</span>'>上一页</a> | "<span>;
        }
        </span><span>if</span>(<span>$next_page</span> > <span>$p_count</span><span>){
            </span><span>echo</span> "下一页 | "<span>;
        }</span><span>else</span><span>{
            </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=<span>$next_page</span>'>下一页</a> | "<span>;
        }
        </span><span>if</span>(<span>$page</span> >= <span>$p_count</span><span>){
            </span><span>echo</span> "最后一页</p>\n"<span>;
        }</span><span>else</span><span>{
            </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=<span>$p_count</span>'>最后一页</a></p>\n"<span>;
        }
    </span>?>
</center>
    <a href="upfile.php">Upload Files</a>
</body>
</html>
ログイン後にコピー

4.画像の閲覧

<html>
<head>
    <meta charset="utf-8">
    <title>后台处理页面</title>
</head>
<body>
<?<span>php
    </span><span>error_reporting</span>(1<span>);
    </span><span>if</span>(<span>$_FILES</span>['upfile']['name'] == <span>NULL</span><span>){
        </span><span>echo</span> "No file choice."<span>;
        </span><span>echo</span> "<a href='upfile.php'>返回</a>"<span>;
    }</span><span>else</span><span>{
        </span><span>$filepath</span> = "/Library/WebServer/Documents/test/images/"<span>;
        </span><span>$tmp_name</span> = <span>$_FILES</span>['upfile']['tmp_name'<span>];
        </span><span>$filename</span> = <span>$filepath</span>.<span>$_FILES</span>['upfile']['name'<span>];
</span><span>//</span><span>        echo $filename;</span><span>if</span>(<span>move_uploaded_file</span>(<span>$tmp_name</span>,<span>$filename</span><span>)){
            </span><span>$dataname</span> = "data.dat"<span>;
            </span><span>$myfile</span> = <span>file</span>(<span>$dataname</span><span>);

            </span><span>if</span>(<span>$myfile</span>[0] == ""<span>){

                </span><span>$fp</span> = <span>fopen</span>(<span>$dataname</span>, "a+"<span>);
                </span><span>fwrite</span>(<span>$fp</span>,"1||".<span>$_FILES</span>['upfile']['name']."||".<span>$_POST</span>["content"]."||".<span>date</span>(Y年m月d日)."\n"<span>);
                </span><span>fclose</span>(<span>$fp</span><span>);
            }</span><span>else</span><span>{
                </span><span>$temp</span> = <span>explode</span>("||", <span>$myfile</span>[0<span>]);
                </span><span>$temp</span>[0]++<span>;
                </span><span>$fp</span> = <span>fopen</span>(<span>$dataname</span>, "r"<span>);
                </span><span>$line_has</span> = <span>fread</span>(<span>$fp</span>,<span>filesize</span>("<span>$dataname</span>"<span>));
                </span><span>fclose</span>(<span>$fp</span><span>);
                </span><span>$fp</span> = <span>fopen</span>(<span>$dataname</span>, "w"<span>);
                </span><span>fwrite</span>(<span>$fp</span>,<span>$temp</span>[0]."||".<span>$_FILES</span>['upfile']['name']."||".<span>$_POST</span>["content"]."||".<span>date</span>("Y年m月d日")."\n"<span>);
                </span><span>fwrite</span>(<span>$fp</span>,"<span>$line_has</span>"<span>);
                </span><span>fclose</span>(<span>$fp</span><span>);
            }

            </span><span>echo</span> "<p></p>"<span>;
            </span><span>echo</span> "指定文件已经上传成功!"<span>;
            </span><span>echo</span> "<p></p>"<span>;
            </span><span>echo</span> "点<a href='index.php'>返回</a>"<span>;
        }</span><span>else</span><span>{
            </span><span>echo</span> "文件上传失败!"<span>;
        }
    }
</span>?>
</body>
</html>
ログイン後にコピー

5.画像を削除します

<html>
<head>
    <meta charset="utf-8">
    <title>相册上传页面</title>
</head>
<body>
    <script language="javascript">
        <span>function</span><span> Juge(theForm){
            </span><span>if</span>(theForm.upfile.value==""<span>){
                alert(</span>"Please choice file!"<span>);
                theForm</span>.upfile.<span>focus();
                </span><span>return</span> (<span>false</span><span>);
            }
            </span><span>if</span>(theForm.content.value==""<span>){
                alert(</span>"Please input image information!"<span>);
                theForm</span>.content.<span>focus();
                </span><span>return</span> (<span>false</span><span>);
            }
            </span><span>if</span>(theForm.content.value.length>60<span>){
                alert(</span>"The information must less than 60 chars."<span>);
                theForm</span>.content.<span>focus();
                </span><span>return</span> (<span>false</span><span>);
            }
        }
    </span></script>
<center>
    <h1>Image album upload page</h1>
    <p>
        <a href="index.php">返回首页</a>
        <table border="1">
            <form enctype="multipart/form-data" action="system.php" method="post"  type="file"></td>
                </tr>
                <tr>
                    <td>输入说明:</td>
                    <td><input name="content" type="text">(*限30字)</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <center>
                            <input type="submit" value="提交">
                            <input type="reset" value="重置">
                        </center>
                    </td>
                </tr>
            </form>
        </table>
    </p>
</center>
</body>
</html>
ログイン後にコピー

以上、PHP フォトアルバム機能の実装について、PHP 画像のアップロード、バックグラウンド管理、閲覧、削除のチュートリアル例を含めて紹介しましたが、PHP チュートリアルに興味のある方の参考になれば幸いです。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート