为每个提交创建一个新页面 - PHP错误

时间:2011-11-05 18:31:53

标签: php mysql html

Here是网站。

我有一个提交页面,以及一个页面的表单操作,用于查询提交信息到我的数据库中。我将在下面包含该代码。我想做的是让它为每个提交创建一个单独的页面。但是,当我尝试上传时,我遇到了大量错误。它上传但绝对不会创建新页面。我有一个模板表格,我会告诉你,但首先,这是上传页面:

<?php
// For use in creating individual page
$tpl_file = "submission.php";
$tpl_path = "/~lyons/templates/";
$submissions_path = "/~lyons/submissions";


// For use in querying submitter name

$username = $_GET['username'];
session_start();
$_SESSION['username'] = $username; 

//Database Information

$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$name = $_POST['name'];
$filename = $_POST['filename'];   
$submitter = $username;
list($width, $height) = getimagesize("$filename");
$type = exif_imagetype($_POST['filename']);

$checkuser = mysql_query("SELECT filename FROM images WHERE filename='$filename'");

$filename_exist = mysql_num_rows($checkuser);

if($filename_exist > 0){
    echo "I'm sorry but this image has already been submitted. Please feel free to try another.";
    unset($filename);
    include 'upload.php';
    exit();
}


if (exif_imagetype($_POST['filename']) == IMAGETYPE_GIF) {
    echo "Sorry, but we can't accept GIFs. Please feel free to try uploading another.";
    unset($filename);
    include 'upload.php';
    exit();
}



$query = "INSERT INTO images (name, filename, submitter, width, height, type)
VALUES('$name', '$filename', '$submitter', '$width', '$height', $type)";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "Thanks for your submission!<br/> Upload another <a href='/~lyons/upload.php'>here</a>!";

$placeholders = array("{name}", "{filename}", "{username}");
$tpl = file_get_contents($tpl_path.$tpl_file);
$new_member_file = str_replace($placeholders, $data, $tpl);
$php_file_name = $username.".php";

$fp = fopen($submissions_path.$php_file_name, "w");
fwrite($fp, $new_submission_file);
fclose($fp); 
?>

这是模板文件(submission.php)

<html>
<title>{name}</title>
<head>
</head>

<body>
<h1>{name}</h1>
Posted by: {username}
<br/>
<img src="{filename}"/>

</body>
</html>

3 个答案:

答案 0 :(得分:1)

看起来您可能遇到路径问题。当您使用路径“/ ~lyons”时,您可能无法指向所需的目录。尝试进行以下更改:

// For use in creating individual page
$tpl_file = "submission.php";
//$tpl_path = "/~lyons/templates/";
$tpl_path = "templates/";

然后请发布新的错误消息(如果有的话)。

答案 1 :(得分:0)

为了帮助您进行调试,请尝试启用错误报告和错误显示。

// add after <?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

打开文件可能会失败,为了更好地控制错误,请尝试以下操作:

$fp = @fopen($submissions_path.$php_file_name, "w");
if (!$fp) {
    die('Failed to open file!  Reason: ' . $php_errormsg);
}

我认为您的路径不正确,很可能需要更改以下两行以使用完整路径。

// change
$tpl_path = "/~lyons/templates/";
$submissions_path = "/~lyons/submissions";

// to
$tpl_path         = $_SERVER['DOCUMENT_ROOT'] . "/~lyons/templates/";
$submissions_path = $_SERVER['DOCUMENT_ROOT'] . "/~lyons/submissions";

当您打开该文件时,它正在尝试打开/~lyons/templates/这是一个不存在的目录,它可能类似于/home/lyons/public_html/templates//home/something/public_html/~lyons/templates或{{1等等/usr/local/apache2/htdocs/~lyons/templates应填写正确的值,但在少数情况下,您可能需要手动设置正确的路径并将其添加到$ tpl_path和$ submissions_path。

答案 2 :(得分:0)

**save the "submission.php" in root folder**
`$tpl_file = "submission.php";`
**create "templates/`" folder in root folder**
`$tpl_path = "templates/";`