Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要PHP上传表单根据下拉列表将文件排序到子目录中_Php_Sorting_Upload_Categories_Subdirectory - Fatal编程技术网

需要PHP上传表单根据下拉列表将文件排序到子目录中

需要PHP上传表单根据下拉列表将文件排序到子目录中,php,sorting,upload,categories,subdirectory,Php,Sorting,Upload,Categories,Subdirectory,我正在尝试实现一个PHP脚本,允许用户为其文件选择适当的类别。选择类别后,脚本应将上载的文件移动到类别对应的目录中。一个示例场景: 类别 第一类 第二类 子目录 cat1=/cat1dir cat2=/cat2dir 现在,用户应该有一个下拉列表,提供两个选项(cat1和cat2)。上传文件后,PHP应自动将文件移动到相应的子目录。我该怎么做呢 虽然我精通技术,但我对PHP知之甚少,似乎无法实现这一点 这是上传表单的脚本 这是表单页面: <html> <head>

我正在尝试实现一个PHP脚本,允许用户为其文件选择适当的类别。选择类别后,脚本应将上载的文件移动到类别对应的目录中。一个示例场景:

类别

  • 第一类
  • 第二类
子目录

  • cat1=/cat1dir
  • cat2=/cat2dir
现在,用户应该有一个下拉列表,提供两个选项(cat1和cat2)。上传文件后,PHP应自动将文件移动到相应的子目录。我该怎么做呢

虽然我精通技术,但我对PHP知之甚少,似乎无法实现这一点

这是上传表单的脚本

这是表单页面:

<html>
<head>
<title>Submissions Script DEV</title>
<style type="text/css">
/**** Start page styles ****/

body {
    background: #DFA01B;
    font-family: arial, sans-serif;
    font-size: 14px;
    }

#wrap {
    max-width: 600px;
    margin: 30px auto;
    background: #fff;
    border: 4px solid #FFD16F;
    -moz-border-radius: 15px;
    -webkit-border-radius: 15px;
    border-radius: 15px;
    padding: 20px;
    }
</style>
<body> 
<div id="wrap">
    <div align="center">
    <a href="http://siteurl.com"><img src="logo.png" /> </a>
    <h1 style="font-family:arial">Submissions</h1>
    <p style="font-family:helvetica"> <i> Welcome to the submission page</i> </p> 
</div>
<form method="POST" action="upload.php" enctype="multipart/form-data">
    <p>
              Please enter your first name: <input type="text" name = "fname">
            <p>
              Please enter your last name: <input type="text" name= "lname">
            <p>
              Student #: <input type="text" name= "snumber"/>
            <p>
            Grade: <select name= "grade">
            <option>9</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
        </select>
        <p>
<hr>
            <!---Upload file section begins--->
              Please attach your Powerpoint (ppt/pptx/zip) file. The file should be     named student#.zip. (For example; 123456.ppt)
        </p>
        <input type="hidden" name="size" value="1024000">
            <input type="file" name="upload"> 

        <p>
        <br/>
        <br/>
        <div align="center">
        <input type=button onClick="location.href='instructions.html'" value='Back'>
        <input TYPE="submit" name="upload" title="Send your submission" value="Submit Portfolio"/>
        </div>
      </form>
<p>   
<!---Footer Styling--->
<div style="font-family: Arial;
font-size: 10px;
color: grey;
align: center;">
<!---Footer Contents--->
    <p>Copyright <a href="http://sitename.com">site</a>site</p>
</div>  
</div>
</body>
</html>

提交脚本开发
/****起始页样式****/
身体{
背景#DFA01B;
字体系列:arial,无衬线;
字体大小:14px;
}
#包裹{
最大宽度:600px;
保证金:30像素自动;
背景:#fff;
边框:4px实心#FFD16F;
-moz边界半径:15px;
-webkit边界半径:15px;
边界半径:15px;
填充:20px;
}
意见书

欢迎来到提交页面 请输入您的名字: 请输入您的姓氏: 学生: 等级: 9 10 11 12


请附上您的Powerpoint(ppt/pptx/zip)文件。该文件应命名为student#.zip。(例如:123456.ppt)



版权网站

这是upload.php(脚本的处理程序)


你能告诉我们到目前为止你有什么吗?是的,我用代码编辑了这篇文章。
<?php

//This is the directory where images will be saved
$extension = explode(".", $_FILES['upload']['name']);
$extension = $extension[count($extension)-1];
$target = "uploads/";
$target = $target . $_POST['snumber'] . "." . $extension;


//This gets all the other information from the form
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$upload=($_FILES['upload']['name']);
$snumber=$_POST['snumber'];
$grade=$_POST['grade'];

// Connects to your Database
mysql_connect("localhost", "db_user", "dbuserpass") or die(mysql_error()) ;
mysql_select_db("sub-data") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO `Submissions` VALUES ('$fname', '$lname', '$snumber', '$grade',         '$upload')") ;

//Writes the upload to the server
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been recorded";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>