-1

根本不是程序员。我被要求为我们的网站开发一个 FTP 页面,并找到了一些看起来很整洁的代码来使它工作。不幸的是(我使用的是 Dreamweaver 6),代码似乎在第 25 行的“if(strleng($error_message)>0)”处中断......我错过了什么?

<?php
$email_to='info@ispitfire.com';
$email_subject = "New file uploaded to FTP";
function died($error) {echo "There was an error uploading your file.";echo $error;die();}
if(!isset($_POST['theirname']) ||
!isset($_POST['email']) ||
!isset($_POST['audioname'])) {
died('Please make sure your name, email address, and the project name are completed.');
}
$theirname = $_POST['theirname'];
$email = $_POST['email'];
$audioname = $_POST['audioname'];
$comments = $_POST['comments'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {$error_message .= "Please input a valid email address.";
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$theirname)) {
$error_message .= "Please avoid using special characters.";
}
if(!preg_match($string_exp,$audioname)) {
$error_message .= "Please use only letters and numbers for Project Name.";
}
**if(strlen($error_message)>0){died($error_message);}clean_string($string){**
$bad = array("content-type","bbc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "A new file has been uploaded to the FTP site\n\n";
$email_message .= "Name: ".clean_string($theirname)."\n";
$email_message .= "Title: ".clean_string($audioname)."\n\n";
$email_message .= "Comments: ".clean_string($comments)."\n\n\n\n";
$headers = 'From: '.$email."\r\n";
if ($_FILES["file1"]["error"]>0) {
$email_message .= "Return Code: " . $_FILES["file1"]["error"] . "\n";
}
else
{
$email_message .= "Upload: " . $_FILES["file1"]["name"] . "\n";
$email_message .= "Type: " . $_FILES["file1"]["type"] . "\n";
$email_message .= "Size: " . ($_FILES["file1"]["size"] / 1024) . " Kb\n";
if ($_FILES["file1"]["type"] == "") {
if (file_exists("upload/" . $_FILES["file1"]["name"])) {
$email_message .= $_FILES["file1"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file1"]["tmp_name"],
"upload/" . $_FILES["file1"]["name"]);
$email_message .= "Stored in: " . "upload/" . $_FILES["file1"]["name"];
}
}
else
{
died("Unsupported file type.");
}
}
@mail($email_to, $email_subject, $email_message, $headers);
header('Location: ftp.html');
?>

这是我第一次涉足 PHP,所以我真的不知道从哪里开始。似乎其他一切工作正常,但由于该特定行上的某些内容,我无法让上传工作。

4

2 回答 2

2
if(strlen($error_message)>0){died($error_message);}clean_string($string){
                                                   ^^^^^^^^^^^^^^^^^^^^^^^

要么你调用 function clean_string(),这意味着最后{的 the 是错误的。如果您尝试 DEFINFE clean_string(),在这种情况下您将丢失function. 例如

if (...) { ... }
function clean_string($string) { ... }

或者

if (...) {... }
clean_string($string);
于 2013-04-03T15:04:43.877 回答
0

应该clean_string($string){怎么做?

应该是if(clean_string($string)) {吗?

或者if(!clean_string($string)) {

还是只有clean_string($string); {

或者 ... ?

于 2013-04-03T15:06:27.130 回答