Reputation: 33
I am using the same PHP from 2 different html pages. I am trying to retain the value of a variable when the PHP page is submitted once again. Below is my code for your reference.
$upload = "E:/Dem";
$str = '';
if(isset($_POST['userid'],$_POST['pid']))
{
$userid = trim($_POST["userid"]);
$pid = trim($_POST["pid"]);
$sql = "SELECT * FROM template WHERE uname = '$userid' and pword = '$pid'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result);
echo "公司".'<br/>';
echo $row['client'].'<br/>'.'<br/>';
echo "第".'<br/>';
echo '<a href="upload.html"/>'.$row['day1'].'</a>'.'<br/>';
$target = $upload.'/'.$row['week'].'/'.$row['day1'].'/'.$row['client'].'/'.$row['brand'].'/'.$row['sc'].'/';
$imagename = $row['week'].'.'.$row['day1'].'.'.$row['client'].'.'.$row['brand'].'.'.$row['sn'].'.'.'jpg';
if($str == '')
{
$str = $target;
}
if(!file_exists($target))
{
mkdir($target,null,0777);
}
$img = $imagename;
}
//echo "$target";
echo "$str".'<br/>';
echo "$img".'<br/>';
if(isset($_FILES['image']))
// image upload
// Want the value of target here.
{
$image = basename($_FILES["image"]["name"]);
echo $str;
move_uploaded_file($_FILES['image']['tmp_name'], $str.$img);
echo "<P>FILE UPLOADED TO: $str</P>";
}
When this PHP is called from the first html page. I am storing the value in $str. The value of $str = $target when this PHP is called from first html page. I want to retain the value of this $str when this PHP is called again from the second HTML page. I want to use the value of this $str to move the uploaded file to the folders and sub-folders created at run-time as shown in the code.
Upvotes: 1
Views: 288
Reputation: 2807
Use session
variable to store the value of $str
in it and use that session variable across multiple pages.
$_SESSION['str'] = $str;
how to use session: http://www.w3schools.com/php/php_sessions.asp
Upvotes: 1