gpt4 book ai didi

php - 如何在同一 php 页面上的其他 php 脚本中使用 php 变量

转载 作者:行者123 更新时间:2023-11-30 23:03:36 29 4
gpt4 key购买 nike

下面是我的源代码,我想在同一页面顶部的另一个 php 脚本中使用位于底部 php 脚本的变量 $r1。我需要一个简单的解决方案来解决这个问题。我想在代码中存在的更新查询中使用该变量。

<?php
$con=mysql_connect("localhost","root","") or die("could not connect to db");

mysql_select_db("test");


$valid_formats = array("jpg", "png", "gif", "zip", "bmp","MP4","3GP");
$max_file_size = 1024*10000; //100 kb
//$path = "uploads/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to execute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
move_uploaded_file($_FILES["files"]["tmp_name"][$f],"uploads/" . $_FILES["files"]["name"][$f]);
// Number of successfully uploaded files
$file="uploads/".$_FILES["files"]["name"][$f];

/* $sql = "Update media set path = '$file' where username = '$r1'";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}*/
}
}
}
}


$sql="select * from media";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
$image=$row[2];
if($image!='')
{
echo "<img src='".$row['path']."' width='175' height='200' />";
}
}



?>

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Multiple File Upload with PHP - Demo</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="wrap">
<h1><a>Multiple File Upload with PHP</a></h1>
<?php
# error messages
if (isset($message)) {
foreach ($message as $msg) {
printf("<p class='status'>%s</p></ br>\n", $msg);
}
}
# success message
if($count !=0){
printf("<p class='status'>%d files added successfully!</p>\n", $count);
}
?>
<p>Max file size 100kb, Valid formats jpg, png, gif</p>
<br />
<br />
<!-- Multiple file upload html form-->


<form action="" method="post" enctype="multipart/form-data">

<span style="font-size:12pt;">Channel: </span> <select name="channels">
<option value="">Channel</option>
<?php


$sql_query="SELECT * FROM media";
$result1 = mysql_query($sql_query) or die(mysql_error());
while($data=mysql_fetch_row($result1))
{
?>
<option value="<?php $r1 = $data[0]; echo $r1;?>" ><?php $r1 = $data[1]; echo $r1 ?></option>
<?php
}

?>

</select>

<input type="file" name="files[]" id="image" multiple="multiple">
<input type="submit" value="Upload">
</form>
</div>
</body>
</html>

最佳答案

如果你想拥有<select name="channels">的值(value)你可以用这个

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){

$r1 = $_POST["channels"];
//your code here

}

希望这对您有所帮助。

关于php - 如何在同一 php 页面上的其他 php 脚本中使用 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22806388/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com