作者roga (凝视)
看板PHP
标题Re: [请益] 图片上传问题..
时间Thu Jan 15 13:11:00 2009
※ 引述《kgfu (好想睡阿!)》之铭言:
: 基本上我写的图片上传都OK,也正常的work!
: 但是我发现一个问题,如果我按F5重新整理,它似乎不会还原到一开始的网页
: 反而又上传同样的图片一次>"<找不到头绪解决这个问题..
: 下面是我一部分的程式码
因为你按下 F5 他就会重作一次你的动作,包含 post 这个动作。
: <form enctype="multipart/form-data" method="post" name="upform">
: <input name="upfile" type="file">
: <input type="submit" value="上传">
: </form>
: ---------------------------
以上这段表单搬到网页最後面。
: <?php
$msg = null;
: if ($_SERVER['REQUEST_METHOD'] == 'POST') {
或是 if(isset($_POST['upfile'])) {
: $filename=$file["tmp_name"];
: $image_size = getimagesize($filename);
: $pinfo=pathinfo($file["name"]);
: $ftype=$pinfo[extension];
: $destination = $destination_folder.time().".".$ftype;
: if (file_exists($destination) && $overwrite != true)
msg .= "<font color='red'>同名文件已经存在了!</a>";
: if(!move_uploaded_file ($filename, $destination))
msg .= "<font color='red'>移动文件出错!</a>";
if($msg == null)
header("Location: $_SERVER['PHP_SELF']");
else
echo $msg;
// 可以简单的避免你的问题。
: }
: ?>
: --------
: 我自己猜测可能问题点在
: $_SERVER['REQUEST_METHOD'] == 'POST'
: 上面...
不是~
--
凝视着,却看不见光景。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.23.32.124
※ 编辑: roga 来自: 211.23.32.124 (01/15 13:12)