dppxp79175 2013-12-10 19:19
浏览 57
已采纳

如何使用PHP,提交和单选按钮复制/重命名/覆盖图像?

I am just starting out with PHP, and I am trying to make a way for a client to be able to change an image using radio buttons and form submission. My intention is for one of 2 image files (Open/Closed.jpg) to be copied and renamed to another location (images/status/Status.jpg) so that coding isn't needed to make the change.

The "new" image will then be used elsewhere. I have tried various copy() and rename() calls, but with no luck. Below is the code I am working with. I feel my problem lies with the submit call, but all things I have tried have not worked. So I am back to my original code (below) trying for a fresher start with help from seasoned users/programmers.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="">
<meta name="keywords" content="">
<title></title>
<link href="style.css" type="text/css" rel="stylesheet" />
</head>

<body>

<?php 
// define variables and set to empty values
$WinterStatusErr = "";
$WinterStatus = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
   if (empty($_POST["WinterStatus"]))
     {$WinterStatusErr = "Status is required";}
   else
     {$WinterStatus = test_input($_POST["WinterStatus"]);}
}
function test_input($data)
{
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
}
?>

<p><span class="error"><font color="red"><b>* required selection</b></font></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
   <input type="radio" name="WinterStatus" <?php if (isset($WinterStatus) &&          $WinterStatus=="open") echo "checked";?>  value="Open">Open
   <input type="radio" name="WinterStatus" <?php if (isset($WinterStatus) && $WinterStatus=="closed") echo "checked";?>  value="Closed">Closed
   <span class="error"><font color="red"><b>* <?php echo $WinterStatusErr;?></b></font></span>
   <br><br>
   <input type="submit" name="submit" value="Submit" <?php
if ($Winterstatus == "Open")
    { copy ("images/Open.jpg", "images/status/Status.jpg"); }
   elseif ($Winterstatus == "Closed")
    { copy ("images/Closed.jpg", "images/status/Status.jpg");}
?>> 
</form>

<?php echo $WinterStatus ?>
</body>
  • 写回答

2条回答 默认 最新

  • dongyou6847 2013-12-10 19:39
    关注

    in php you can use exec() to execute a command. on linux the "cp" command should do what you are asking. Permission/security issues will be a problem though, so i would recommend just changing a variable to the new image rather then actually moving it...a lot simpler and safer -- if I knew where you reference the image I could help you figure that out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图