我想将不同类型的文件压缩到某个目录,我正在努力让这个脚本正常工作,我在snipplr上找到但是它没有工作,因为我认为它会,这是我的代码。< / p>
别介意我的代码中有一个额外的逗号
更新:我在下面的评论中添加了更多代码,我还要将文件名添加到datatbase中的字段,目前我打破了页面的脚本没有加载我不知道为什么因为它似乎在我拥有的其他页面上工作。
<?php
if( isset($_POST['submit']) )
{
$target_path = "../downloads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
/*
$title = basename( $_FILES['uploadedfile']['name']);
$sql = sprintf("INSERT INTO forms (title)VALUES('%s')",
mysql_real_escape_string($title)
);
$results = mysql_query($sql)or die(mysql_error());
*/
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<input type="file">
<input type="submit" name="submit" value="submit" />
</form>
答案 0 :(得分:0)
除了现有目录,文件权限等,您可能希望为输入命名:
<input type="file" name="uploadedfile">