amin7x
جمعه 13 اردیبهشت 1392, 20:17 عصر
سلام دوستان
من یک مشکلی دارم ، توی این کد من فایل اپلود نمیشه و اسم اون توی DB ذخیره نمیشه.
ولی بقیه مقادیر ذخیره میشه.
<form action="" method="post" name="Addnews" enctype="multipart/form-data">
<P>Title News :</P>
<input type="text" name="TitleNews" />
<P>Contact News :</P>
<textarea name="ContactNews" cols="30" rows="6"></textarea>
<p>Upload Image : (Max Upload 2MB , format .gif & .jpeg)</p>
<input name="file" type="file" />
<br />
<input type="submit" value="Insert News" name="InsertNews" />
</form>
if(isset($_POST['InsertNews'])){
$TitleNews = mysql_real_escape_string(htmlspecialchars($_POST['TitleNews']));
$ContactNews = mysql_real_escape_string(htmlspecialchars($_POST['ContactNews']));
if(!empty($TitleNews) && !empty($ContactNews)){
if(!empty($_POST['file'])){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
$Error = "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("../images/Upload/" . $_FILES["file"]["name"]))
{
$FileName = $_FILES["file"]["name"].rand();
move_uploaded_file($_FILES["file"]["tmp_name"],"../images/Upload/" . $FileName);
$Accepti = "And imgaes is uploaded";
}
else
{
$FileName = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"../images/Upload/" . $FileName);
$Accepti = "And imgaes is uploaded";
}
}
}
else
{
$FileInvalid = "Invalid file";
}
}
if(isset($FileName)) {$File = $FileName;}
if(mysql_query("INSERT INTO `news` (`titlenews`, `contentnews`, `img`) VALUES ('{$TitleNews}', '{$ContactNews}', '{$File}')",$ConnectionVar))
{
$Accept = "News was shear";
}
}
else{
$EmptyFild = "please type all fild";
}
}
?>
ممنون مشم کمکم کنید.
این اروری که میده :
Notice: Undefined variable: File in ... On line 43
من یک مشکلی دارم ، توی این کد من فایل اپلود نمیشه و اسم اون توی DB ذخیره نمیشه.
ولی بقیه مقادیر ذخیره میشه.
<form action="" method="post" name="Addnews" enctype="multipart/form-data">
<P>Title News :</P>
<input type="text" name="TitleNews" />
<P>Contact News :</P>
<textarea name="ContactNews" cols="30" rows="6"></textarea>
<p>Upload Image : (Max Upload 2MB , format .gif & .jpeg)</p>
<input name="file" type="file" />
<br />
<input type="submit" value="Insert News" name="InsertNews" />
</form>
if(isset($_POST['InsertNews'])){
$TitleNews = mysql_real_escape_string(htmlspecialchars($_POST['TitleNews']));
$ContactNews = mysql_real_escape_string(htmlspecialchars($_POST['ContactNews']));
if(!empty($TitleNews) && !empty($ContactNews)){
if(!empty($_POST['file'])){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
$Error = "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("../images/Upload/" . $_FILES["file"]["name"]))
{
$FileName = $_FILES["file"]["name"].rand();
move_uploaded_file($_FILES["file"]["tmp_name"],"../images/Upload/" . $FileName);
$Accepti = "And imgaes is uploaded";
}
else
{
$FileName = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"../images/Upload/" . $FileName);
$Accepti = "And imgaes is uploaded";
}
}
}
else
{
$FileInvalid = "Invalid file";
}
}
if(isset($FileName)) {$File = $FileName;}
if(mysql_query("INSERT INTO `news` (`titlenews`, `contentnews`, `img`) VALUES ('{$TitleNews}', '{$ContactNews}', '{$File}')",$ConnectionVar))
{
$Accept = "News was shear";
}
}
else{
$EmptyFild = "please type all fild";
}
}
?>
ممنون مشم کمکم کنید.
این اروری که میده :
Notice: Undefined variable: File in ... On line 43