我正在编写一个将文件上传到 MySQL 数据库的脚本。我收到一条错误消息:
Notice: Undefined variable: code in C:\wamp\www\application\letters.php on line 82
这是 ** 中的字代码。任何可以发现错误的人请告诉我。
if ($name)
if ($title && $description)
{
$date = date("d m Y");
$charset ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
//length of value to generate
$length = 15;
//create variable and run through and randomly select fromcharset.
for ($i = 0; $i <= $length; $i++)
{
//position to start at. rand function.
$rand = rand() % strlen($charset);
$tmp = substr($charset, $rand, 1);
//append onto code
**$code .= $tmp;**
}
//checking for existence of code which is generated.
$query= mysql_query("SELECT code FROM letter_details WHERE code = '$code'");
//if code is found
$numrows = mysql_num_rows($query);
// if that code exists, generate code again
while ($numrows != 0)
{
for ($i=0; $i <= $length; $i++)
{
//position to start at. rand function.
$rand = rand() % strlen($charset);
$tmp = substr($charset, $rand, 1);
//append onto code
$code .=$tmp;
}
//checking for existence of code which is generated.
$query= mysql_query("SELECT code FROM letter_details WHERE code = '$code'");
//if code is found
$numrows = mysql_num_rows($query);
}
//create directory
mkdir("files/$code");
//put file into it
move_uploaded_file($tmpname, "files/$code/"."$name".$ext);
$query = mysql_query("INSERT INTO letter_details VALUES ('$letter_id', $title','$code','$description','$student_info_id', '$staff_info_id', '$date')");
echo "Your file '$title' was Succesfully uploaded.<br><br><a href='download.php?file=$code'>Download</a>";