我已经看过几次这段代码了,仍然看不到出什么问题了。这段代码是[url] /sig/index.php的内容。每次运行它,都会收到“对不起,有一个错误”。但是,当我检查新文件和旧文件的值时,我试图复制它们就可以了。我在做蠢事吗?我在同一台服务器的其他页面上使用了复制功能,因此我确定代码一定有问题。
这是一个简单的页面,用于将文件复制到同一目录中,并覆盖先前的文件。我知道源文件存在,因为我有一个“测试到源文件的链接”始终有效。
<?php
$formval = $_POST["banners"] ;
$newname = "banner-main.png" ;
$dir = "/sig/" ;
$img_to_copy = $dir . $formval . ".png" ;
$newimg = $dir . $newname ;
if (copy($img_to_copy, $newimg)) {
echo ($formval . " is the new email signature image.") ;
} else {
echo "Sorry, there was an error.";
} ;
echo '<a href="' . $img_to_copy . '?var=' . rand(0,1000000) . '" target="_blank">Test link to source file</a>' ;
?>
<h1>Which banner is next?</h1>
<br>
<form action="/sig/index.php" method="post">
<input type="radio" name="banners" value="banner-1">Banner 1
<br>
<input type="radio" name="banners" value="banner-2">Banner 2
<br>
<input type="radio" name="banners" value="banner-3">Banner 3
<br>
<input type="radio" name="banners" value="banner-4">Banner 4
<br>
<input type="submit" value="Submit">
</form>
最有可能是您的问题的原因是您在那里的$dir = "/sig/"
。
[以HTML格式查看文件时,它使用您的域/项目的Web服务器DocumentRoot中的文件夹sig/
。
复制此文件时,将使用文件系统根目录中的文件夹sig/
(该文件不存在)。
复制文件时将$dir = "/sig/"
更改为$dir = "./sig/"
或使用完整文件系统路径。