周围有很多版本,但我无法正确...
我需要将变量从一个 php 脚本文件传输到另一个。
script1.php
有变量:
$t1 = $_POST['t1'];
$t2 = $_POST['t2'];
我需要在另一个脚本文件中使用这些变量 -script2.php
如何访问script2.php
文件中的这些变量?
好的。我将发布所有脚本。
script1.php 或实际上 getImage.php 如下
<?php
$today = date("Ymd_His");
$t1 = $_POST['t1']; //mazais nosaukums
$t2 = $_POST['t2']; //lielais nosaukums
$c1 = $_POST['c1']; //kjeksis
$c2 = $_POST['c2']; //kjeksis
$c3 = $_POST['c3']; //kjeksis
$c4 = $_POST['c4']; //kjeksis
$mazais = $_POST['mazais']; //maza bilde atseviskji
$lielais = $_POST['lielais']; //maza bilde atseviskji
$response = "";
$error_response = "error.php";
$succes_response = "nextstep.php";
$etikjete = base64_decode($_REQUEST['png']);
if ($handle1 = fopen("render/".$today.'.png', 'w+')) {
if (!fwrite($handle1, $etikjete) === FALSE) {
fclose($handle1);
$response .= "Success etikjete! ";
} else {
$response .= "fwrite error etikjete! ";
$error = true;
}
} else {
$response .= "fopen error etikjete! ";
$error = true;
}
if($mazais){
$etikjete = base64_decode($mazais);
if ($handle1 = fopen("render/".$today.'_mazais.png', 'w+')) {
if (!fwrite($handle1, $etikjete) === FALSE) {
fclose($handle1);
$response .= "Success mazais! ";
} else {
$response .= "fwrite error mazais! ";
$error = true;
}
} else {
$response .= "fopen error mazais! ";
$error = true;
}
}
if($lielais){
$etikjete = base64_decode($lielais);
if ($handle1 = fopen("render/".$today.'_lielais.png', 'w+')) {
if (!fwrite($handle1, $etikjete) === FALSE) {
fclose($handle1);
$response .= "Success lielais! ";
} else {
$response .= "fwrite error lielais! ";
$error = true;
}
} else {
$response .= "fopen error lielais! ";
$error = true;
}
}
if($error){
echo $error_response;
} else {
echo $succes_response;
}
?>
这里的 script2.php 被称为 nextstep.php ,在这个 nextstep.php 中,我需要将 getImage.php 中的变量保存到数据库中。nextstep.php 到目前为止是这样但不起作用。与 db 的连接没问题,如果我在 nextstep.php 上设置不同的自变量,那么它们将存储到 db 中。
<?php
include 'getImage.php';
// Connects to your Database
mysql_connect("localhost", "user", "pass") or die(mysql_error()) ;
mysql_select_db("myDB") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO jos_orders (maza_bilde,liela_bilde,mazais_nosaukums,lielais_nosaukums)
VALUES ('$t1', '$c2', '$mazais', '$lielais')") ;
?>