大家好,抱歉我的英语不好。 我有3个页面:index.php,header.php和openloghi.php。 我的问题是在header.php中。我尝试根据用户的选择(从他的电脑或服务器文件夹)生成$ logo变量。选择机制是可以的,问题是更改没有应用于$ logo,保持空白。我在哪里弄错了? ps我是初学者
的header.php
<?php
$folder = 'Loghi/';
$logo="";
if(isset($_FILES['userfile'])){
$target_dir='C:/Users/*******/Documents/offline/htdocs/Books/Loghi/';
$img_temp=$_FILES['userfile']['tmp_name'];
$img_name=$_FILES['userfile']['name'];
$img_type=$_FILES['userfile']['type'];
$img_size=$_FILES['userfile']['size'];
$homepage= '<a id="comeback" href="'.$_SERVER['HTTP_REFERER'].'">bla bla</a>';
if($img_size > 1048576){
echo "bla bla bla";
echo $homepage;
} elseif (file_exists($target_dir . basename($img_name))){
echo "bla bla bla.";
echo $homepage;
} elseif (($img_type!= "image/png")&&($img_type!= "image/jpg")&&($img_type!= "image/jpeg")) {
echo "bla bla bla.";
echo $homepage;
} else {
if((move_uploaded_file($img_temp, $target_dir.$img_name))){
echo "bla bla bla.";
echo $homepage;
$logo=$target_dir.$img_name;
} else {
echo "bla bla bla.";
}
}
}
?>
<?php
// post sent from openloghi.php
if (!empty($_POST['immagine']))
{
$logo=$folder.$_POST['immagine'];
echo "<a href='index.php'> bla bla</a>";
}
?>
的index.php
<?php include('header.php');
?>
<div id=header>
<a href="index.php"><img id="logo" src="<?php echo $logo; ?>" alt=""/></a>
</div>
<div id="change_logo">
<form action='header.php' method="post" enctype="multipart/form-data" name="form1">
<span class="bold">bla bla</span>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
<input name="userfile" type="file">
<input type="submit" name="submit" value="bla bla">
<button type="reset">bla bla</button>
</form>
<form action='openloghi.php' method="post" name="form2">
<input type="submit" name="submit2" value="bla bla">
</form>
</div>
谢谢!