PHP我可以在变量示例中放置一个全局变量:$names=$_FILES[";dfile";];

PHP我可以在变量示例中放置一个全局变量:$names=$_FILES[";dfile";];,php,html,global-variables,Php,Html,Global Variables,试图建立一个上传文本和图像的管理面板这里是html页面。Html页面工作正常是php页面被破坏了Html只是作为参考 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <title>Administartor Panel</title> <head> <link rel="stylesheet" type="text/css" href="

试图建立一个上传文本和图像的管理面板这里是html页面。Html页面工作正常是php页面被破坏了Html只是作为参考

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<title>Administartor Panel</title>
<head>
<link rel="stylesheet" type="text/css" href="admin.css" />
</head>
<body>
<h1>Heritage House Administartor Panel</h1>
<br/>
<h2>
<a href="#eone">Event One</a>&nbsp;
<a href="#etwo">Event Two</a>&nbsp;
<a href="#ethree">Event Three</a>&nbsp;
<a href="#efour">Event Four</a>&nbsp;
<a href="#efive">Event Five</a>&nbsp;
<a href="#esix">Event Six</a>&nbsp;
</h2>
<br/>
<table>
<tr>
<td id="eone">
<br/>
<p>Event One</P>
<p> Please name the picture file1 before uploading.</p>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="afile" id="afile" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<form action="WriteTxt1.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for artical One:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>
<tr>
<td id="etwo">
<p >Event Two</P>
<p> Please name the picture file2 before uploading.</p>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="bfile" id="bfile" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<form action="WriteTxt2.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for artical Two:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>
<tr>
<td id="ethree" >
<p >Event Three</P>
<p> Please name the picture file3 before uploading.</p>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="cfile" id="cfile" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<form action="WriteTxt3.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for artical Three:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>
<tr>
<td id="efour" >
<p >Event Four</P>
<p> Please name the picture file4 before uploading.</p>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="dfile" id="dfile" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<form action="WriteTxt4.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for artical Four:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>
<tr>
<td id="efive" >
<p >Event Five</P>
<p> Please name the picture file5 before uploading.</p>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="efile" id="efile" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<form action="WriteTxt5.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for artical Five:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>
<tr>
<td id="esix" >
<p >Event Six</P>
<p> Please name the picture file6 before uploading.</p>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="ffile" id="file6" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<form action="WriteTxt6.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for artical Six:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>
</body>
</html>
也许你应该用

isset($_FILES["afile"])
而不是

file_exists($_FILES["afile"]["tmp_name"])
--编辑

回答标题中的问题:如果设置了,例如$_FILES[“afile”],则有可能。这样,您的新变量中就有了一个数组。

也许您应该使用

isset($_FILES["afile"])
而不是

file_exists($_FILES["afile"]["tmp_name"])
--编辑


回答标题中的问题:如果设置了,例如$_FILES[“afile”],则有可能。这样,新变量中就有了一个数组。

非常接近实际工作

//Uses $names as a key in $_FILES - no single quotes for variable expansion....
$ext = findexts($_FILES[$names]['name']);
我还建议使用某种循环,而不是一个大的elseif和一堆粘贴的代码。使用了两个改进:在$\u文件数组上,以及

foreach($\u文件为$fileKey=>$value)
{
//设置$type、$size、$name、$tmp_name、$error
提取价值(美元);
//这将函数应用于我们的文件
$ext=findexts($name);
//这将指定要保存到的子目录。
$targett=“表格/上传/”;
//这将合并目录、新文件名和扩展名
$target=$targett.$new.$ext;
//确保图像符合规格
如果(($type==“image/gif”)
||($type==“图像/jpeg”)
||($type==“图像/pjpeg”))
&&(200万美元以下)
{
如果($error>0)
{
回显“返回代码:.”错误。“
”; } 其他的 { 回声:“谢谢你!”; } //保存上传的文件 如果(文件_存在(“forms/upload/”$name)) { 移动上传的文件($tmp\U名称,$target); echo$name。“旧文件已重写。”; } 其他的 { 移动上传的文件($tmp\U名称,$target); echo“存储在:“.”forms/upload/“$name; } } }
非常接近实际工作

//Uses $names as a key in $_FILES - no single quotes for variable expansion....
$ext = findexts($_FILES[$names]['name']);
我还建议使用某种循环,而不是一个大的elseif和一堆粘贴的代码。使用了两个改进:在$\u文件数组上,以及

foreach($\u文件为$fileKey=>$value)
{
//设置$type、$size、$name、$tmp_name、$error
提取价值(美元);
//这将函数应用于我们的文件
$ext=findexts($name);
//这将指定要保存到的子目录。
$targett=“表格/上传/”;
//这将合并目录、新文件名和扩展名
$target=$targett.$new.$ext;
//确保图像符合规格
如果(($type==“image/gif”)
||($type==“图像/jpeg”)
||($type==“图像/pjpeg”))
&&(200万美元以下)
{
如果($error>0)
{
回显“返回代码:.”错误。“
”; } 其他的 { 回声:“谢谢你!”; } //保存上传的文件 如果(文件_存在(“forms/upload/”$name)) { 移动上传的文件($tmp\U名称,$target); echo$name。“旧文件已重写。”; } 其他的 { 移动上传的文件($tmp\U名称,$target); echo“存储在:“.”forms/upload/“$name; } } }
重复的代码太多了!你真的需要6个单独的HTML表单吗?为什么没有一个表单,可以用下拉菜单选择事件

<select name="event">
    <option value="afile">Event One</option>
    <option value="bfile">Event Two</option>
    ...etc
</select>

这是一个大量的重复代码!你真的需要6个单独的HTML表单吗?为什么没有一个表单,可以用下拉菜单选择事件

<select name="event">
    <option value="afile">Event One</option>
    <option value="bfile">Event Two</option>
    ...etc
</select>

我只是想感谢每一位给我的问题留下答案的人。我对我的问题回复时间如此之短感到非常惊讶。在尝试并测试了你的答案之后,我仍然没有找到任何真正解决问题的方法。直到我发现我忘记结束一个if语句,我才开始朝着一个答案前进

 if ((($type == "image/gif")
    || ($type == "image/jpeg")
    || ($type == "image/pjpeg"))
    && ($size < 2000000))
      {
if(($type==“image/gif”)
||($type==“图像/jpeg”)
||($type==“图像/pjpeg”))
&&(200万美元以下)
{
既然这个if语句有了一个结尾,我有时间研究你的所有答案,我相信我会很快让这一页符合我的喜好。 它现在正在工作,但它们仍然需要改进

HTML


管理员小组
遗产管理人小组


事件上载程序

请选择要编辑的事件。 事件1 事件2 事件3 事件4 事件5 事件6
请在此上传您的活动图片文件

照片:

为事件文章输入文本:
PHP
//此函数将扩展名与文件名的其余部分分开并返回它
函数findexts($filename)
{
$filename=strtolower($filename);
$exts=split(“[/\\.]”,$filename);
$n=计数($exts)-1;
$exts=$exts[$n];
返回$exts;
} 
//此if语句将新文件名分配给html表单选择中选项菜单的值中的变量。
$new=$_POST[“selection”]。”;
//这将函数应用于我们的文件
$ext=findexts($_FILES[“file”][“name”]);
//这将指定要保存到的子目录。
$targett=“表格/上传/”;
//这将合并目录、新文件名和扩展名
$target=$targett.$new.$ext;
//确保图像符合规格
如果(($_文件[“文件”][“类型”]=“图像/gif”)
||($_文件[“文件”][“类型”]=“图像/jpeg”)
||($_文件[“文件”][“类型”]=“图像/pjpeg”))
&&($_文件[“文件”][“大小”]<2000000))
{
回显“文件检查通过
”; } //如果文件不符合标准,则会出错 如果($\u文件[“文件”][“错误”]>0) { 回显“返回代码:”.$\u文件[“文件”][“错误”]。“
”; } 其他的 { 回声:“谢谢你!”; } //保存上传的文件 如果(文件存在(“forms/upload/”$\u FILES[“file”][“name”])) { 移动上传的文件($文件[“文件”][“tmp文件名”],$target); 回音$FIL
 if ((($type == "image/gif")
    || ($type == "image/jpeg")
    || ($type == "image/pjpeg"))
    && ($size < 2000000))
      {
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!-- 
html admin page for HH 
-->
<title>Administartor Panel</title>
<head>
<link rel="stylesheet" type="text/css" href="admin.css" />
</head>
<body>
<h1>Heritage House Administartor Panel</h1>
<br/>
<table>
<tr>
<td id="eone">
<br/>
<p>Event Uploader</P>
<form action="formupload.php" method="post"
enctype="multipart/form-data">
<label for="selection">Please select the event you would like to edit.</label>
<select name="selection">
<option value="file1">Event1</option>
<option value="file2">Event2</option>
<option value="file3">Event3</option>
<option value="file4">Event4</option>
<option value="file5">Event5</option>
<option value="file6">Event6</option>
</select>
<br />
<p> Please upload your event picture file here.</p>
<p align="center">
<label for="file">Photo:</label>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Upload" />
</p>
</form>
<form action="WriteTxt1.php" method="post"
enctype="multipart/form-data">
<label for="file">Input Text for the event artical:</label>
<textarea rows="25" cols="100" name="content">
</textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
</td>
</tr>

</form>
</td>
</tr>
</body>
</html>
    //This function separates the extension from the rest of the file name and returns it
    function findexts ($filename)
    {
    $filename = strtolower($filename) ;
    $exts = split("[/\\.]", $filename) ;
    $n = count($exts)-1;
    $exts = $exts[$n];
    return $exts;
    } 
    //This if statement assigns the new file name to a variable from the value of the options menu in the html form selection.
 $new = $_POST ["selection"] . "."; 
    //This applies the function to our file
    $ext = findexts ($_FILES ["file"] ["name"]) ;
        //This assigns the subdirectory you want to save into.
        $targett = "forms/upload/";
        //This combines the directory, the new file name, and the extension
        $target = $targett . $new.$ext; 
        // makes sure image meets specs
    if ((($_FILES ["file"] ["type"] == "image/gif")
    || ($_FILES ["file"] ["type"] == "image/jpeg")
    || ($_FILES ["file"] ["type"] == "image/pjpeg"))
    && ($_FILES ["file"] ["size"]< 2000000))
      {
      echo "file check pass<br />";
      }
      //makes an error if file does not meet standards 
      if ( $_FILES ["file"] ["error"] > 0)
        {
        echo "Return Code: " . $_FILES ["file"] ["error"] . "<br />";
        }
      else
        {
        echo "Thank You! <br />";
        }
    //saves uploaded file
        if (file_exists("forms/upload/" . $_FILES ["file"] ["name"]))
          {
          move_uploaded_file( $_FILES ["file"]["tmp_name"], $target);
          echo $_FILES ["file"] ["name"] . " Old File Over Written. ";
          }
        else
          {
          move_uploaded_file( $_FILES["file"]["tmp_name"], $target);
          echo "Stored in: " . "forms/upload/" . $_FILES ["file"] ["name"];
          }   
?>
<html>
<!-- 
html to return user to admin page 
-->
<title>
Upload Result
</title>
<head>
<p>
<br />
Back To Admin Page
</p>
</head>
<body>
<form action="">
<a href="adminarea.html">
<input type="button" value="Back" />
</a>
</form>
</body>
</html>