【发布时间】:2017-06-03 23:35:20
【问题描述】:
我正在使用 php 进行搜索功能,我也需要将</pages> 添加到我正在编写的文件的末尾。 </pages> 只能写一次,最后。
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]
["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
// Check if file already exists
if (file_exists($target_file)) {
echo "ERR: 418 (File all ready exists)\n";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "ERR: 418 (File too large)\n";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "txt") {
echo "ERR: 418 (Supported file types - .txt)\n";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
$target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). "
has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$contentsbro = file_get_contents("links.xml");
$myfile = fopen("links.xml", "w") or die("Unable to open file!");
$txt = "<link><title>". basename( $_FILES["fileToUpload"]["name"]). "
</title>
<url>https://fidead.000webhostapp.com/uploads/". basename(
$_FILES["fileToUpload"]["name"]). "</url>
</link>";
$txto = $contentsbro . $txt;
fwrite($myfile, $txto);
fclose($myfile);
?>
我需要知道如何在最后写一次字符串,否则会报错。
【问题讨论】: