html - how to terminate php code

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

What I wrote is a subpage that receives form data. This subpage receives a data and automatically generates two corresponding files in the directory based on the received data. Now I want to add a judgment that if the file exists, it will not be executed to generate two files. If the code of a file does not exist, execute the code to generate the file (now only output whether the link exists) my code looks like this

<code><html>
<head>
<title>XXX</title>
</head>
<body>
<?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."";
     
}
; ?>
</body>
</html>

</code>
Copy after login
Copy after login

Baidu found an exit function that looks like this

<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

But if you add <?php ?> directly, it will become php nested within php, and you will be stuck in a puzzle
If the answer you gave me is exit or die, I will write it like this

<code><html>
<head>
<title>XXX</title>
</head>
<body>
<?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
'); ?>

")
}; ?>
</body>
</html>
这样的话变成php套嵌php 会报错的</code>
Copy after login
Copy after login

Reply content:

What I wrote is a subpage that receives form data. This subpage receives a data and automatically generates two corresponding files in the directory based on the received data. Now I want to add a judgment that if the file exists, it will not be executed to generate two files. If the code of a file does not exist, execute the code to generate the file (now only output whether the link exists) my code looks like this

<code><html>
<head>
<title>XXX</title>
</head>
<body>
<?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."";
     
}
; ?>
</body>
</html>

</code>
Copy after login
Copy after login

Baidu found an exit function that looks like this

<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

But if you add <?php ?> directly, it will become php nested within php, and you will be stuck in a puzzle
If the answer you gave me is exit or die, I will write it like this

<code><html>
<head>
<title>XXX</title>
</head>
<body>
<?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
'); ?>

")
}; ?>
</body>
</html>
这样的话变成php套嵌php 会报错的</code>
Copy after login
Copy after login

Wouldn’t it be better to just do this...

<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>
Copy after login

update:

<code class="php"><html>
<head>
    <title>XXX</title>
</head>
<body>
<?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 
 ');
?>
</body>
</html></code>
Copy after login

<code><html>
<head>
<title>XXX</title>
</head>
<body>
<?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'); 
?>
</body>
</html></code>
Copy after login

Change it to this

If it is already within the <?php tag, there is no need to write it again. .

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