html - 怎么终止php代码

WBOY
Release: 2016-07-06 13:51:28
Original
1231 people have browsed it

我写的是一个接收表单数据的子页面 这个子页面接收一个数据然后根据接收来的数据 自动在目录下生成两个对应的文件 现在我想加个判断 如果文件存在就不执行生成两个文件的代码 如果不存在就执行生成文件的代码 (现在只输出链接存不存在)我的代码大概长这样

<code>

<title>XXX</title>


<?php $filename = @$_POST['数据1']."/index.htm";
if(!file_exists($filename)){mkdir(@$_POST['数据1']);}
file_put_contents($filename,'文件内容1
'); ?>
<?php $file = @$_POST['数据1']."/233.htm";
file_put_contents($file,'文件内容2
'); ?>
<?php $dir = @$_POST['数据1'];
$file = @$_POST['数据1']."/index.htm";
if(file_exists($file))
{
    echo "链接已存在 www.XXX.com/".$dir."";
    
}
else 

{
    echo "您的链接是".$dir."";
     
}
; ?>



</code>
Copy after login
Copy after login

百度找到个exit函数大概是这样

<code><?php $site = "http://www.w3school.com.cn/";
fopen($site,"r")
or exit("Unable to connect to $site");

?>

</code>
Copy after login
Copy after login

但是直接加上 <?php ?>的话不就变成php套嵌php了 陷入无解中
如果你们给我的答案是exit或者die我写出来是这样

<code>

<title>XXX</title>


<?php $dir = @$_POST['数据1'];
$file = @$_POST['数据1']."/index.htm";
if(file_exists($file))
{
    echo "链接已存在 www.XXX.com/".$dir."";
    
}
else 

{
    echo "您的链接是".$dir."";
    exit("
    
<?php
$filename = @$_POST['数据1']."/index.htm";
if(!file_exists($filename)){mkdir(@$_POST['数据1']);}
file_put_contents($filename,'文件内容1
'); ?>
<?php $file = @$_POST['数据1']."/233.htm";
file_put_contents($file,'文件内容2
'); ?>

")
}; ?>


这样的话变成php套嵌php 会报错的</code>
Copy after login
Copy after login

回复内容:

我写的是一个接收表单数据的子页面 这个子页面接收一个数据然后根据接收来的数据 自动在目录下生成两个对应的文件 现在我想加个判断 如果文件存在就不执行生成两个文件的代码 如果不存在就执行生成文件的代码 (现在只输出链接存不存在)我的代码大概长这样

<code>

<title>XXX</title>


<?php $filename = @$_POST['数据1']."/index.htm";
if(!file_exists($filename)){mkdir(@$_POST['数据1']);}
file_put_contents($filename,'文件内容1
'); ?>
<?php $file = @$_POST['数据1']."/233.htm";
file_put_contents($file,'文件内容2
'); ?>
<?php $dir = @$_POST['数据1'];
$file = @$_POST['数据1']."/index.htm";
if(file_exists($file))
{
    echo "链接已存在 www.XXX.com/".$dir."";
    
}
else 

{
    echo "您的链接是".$dir."";
     
}
; ?>



</code>
Copy after login
Copy after login

百度找到个exit函数大概是这样

<code><?php $site = "http://www.w3school.com.cn/";
fopen($site,"r")
or exit("Unable to connect to $site");

?>

</code>
Copy after login
Copy after login

但是直接加上 <?php ?>的话不就变成php套嵌php了 陷入无解中
如果你们给我的答案是exit或者die我写出来是这样

<code>

<title>XXX</title>


<?php $dir = @$_POST['数据1'];
$file = @$_POST['数据1']."/index.htm";
if(file_exists($file))
{
    echo "链接已存在 www.XXX.com/".$dir."";
    
}
else 

{
    echo "您的链接是".$dir."";
    exit("
    
<?php
$filename = @$_POST['数据1']."/index.htm";
if(!file_exists($filename)){mkdir(@$_POST['数据1']);}
file_put_contents($filename,'文件内容1
'); ?>
<?php $file = @$_POST['数据1']."/233.htm";
file_put_contents($file,'文件内容2
'); ?>

")
}; ?>


这样的话变成php套嵌php 会报错的</code>
Copy after login
Copy after login

直接这样不就好了吗...

<code class="php"><?php $dir = @$_POST['数据1'];
$filename = $dir . "/index.htm";
if (file_exists($filename)) {
    echo "链接已存在 www.XXX.com/" . $dir . "\n";

    exit("链接已存在");
} else {
    mkdir($dir);
}
file_put_contents($filename, '文件内容1 ');

//另外一个文件一样做
//$file = $dir . "/233.htm";
//file_put_contents($file, '文件内容2 ');
</code></code>
Copy after login

update:

<code class="php">

    <title>XXX</title>


<?php $dir = @$_POST['数据1'];
//$dir = 'test223';
$filename = $dir . "/index.htm";
if (file_exists($filename)) {

    echo "链接已存在 www.XXX.com/:2333" . $dir . "\n";
    exit("链接已存在");
} else {

    if (!file_exists($dir)) {
        mkdir($dir);
        echo "您的链接是" . $dir . "";
    }
}
file_put_contents($filename, '
 文件内容1
  ');
$file = $dir . "/233.htm";
file_put_contents($file, '
 文件内容2 
 ');
?>

</code>
Copy after login

<code>

<title>XXX</title>


<?php $dir = @$_POST['数据1'];
$filename = @$_POST['数据1']."/index.htm";
if(file_exists($filename ))
{
    echo "链接已存在 www.XXX.com/".$dir."";
    exit();
}
else 
{
    echo "您的链接是".$dir."";
    mkdir(@$_POST['数据1']);;
   
}; 
file_put_contents($filename,'文件内容1'); 
$file = @$_POST['数据1']."/233.htm";
file_put_contents($file,'文件内容2'); 
?>

</code>
Copy after login

改成这样

如果已经在<?php 标签内的,不需要再写一遍。。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!