1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>News (add - preview)</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
if ($_POST) {
$title = $_POST['title'];
$post = $_POST['post'];
$titleimg = $_POST['titleimg'];
$linkupload = $_POST['linkupload'];
}
if (IsSet($_POST['add']))
{
$target_path = "uploads/";
$target_path1 = $target_path . basename( $_FILES['fileupload']['name']);
if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_path1)) {
$errimg = "The file ". basename( $_FILES['fileupload']['name'])." has been uploaded";
} else{
$errimg .= "There was an error uploading the file, please try again!";
}
echo $errimg;
//-------------
$url = $linkupload;
// the path of save
$path = 'uploads/';
$exp = explode('/',$url);
$serv = $exp[0].'//'.$exp[2];
// the name of file
$filename = array_pop($exp);
//
$xcontext = stream_context_create(array("http"=>array("header"=>"Referer: ".$serv."\r\n")));
$content = file_get_contents($url,false,$xcontext);
if ($content === false) {
echo "\nImpossible to get file.";
exit(1);
}
$test = file_put_contents($path.'/'.$filename,$content);
if ($test === false) {
echo "\nImpossible to save the file.";
exit(1);
}
// All it's OK
echo "\nSaving file successfull.";
$target_temp_path2 = $path.'/'.$filename;
//--------------
// do the insert here
//$sql = 'INSERT INTO your_table ...';
echo '<meta http-equiv="refresh" content="2; url=addnews.php" />';
//header("Location: addnews.php");
}
elseif (IsSet($_POST['prev'])) {
$target_temp_path = "tempo/";
$target_temp_path1 = $target_path . basename( $_FILES['fileupload']['name']);
if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_temp_path1)) {
$errimg = "The file ". basename( $_FILES['fileupload']['name'])." has been uploaded\n";
} else{
$errimg .= "There was an error uploading the file ".basename( $_FILES['fileupload']['name']).", please try again!\n";
}
?>
<div style="display:block;">
<p><b>Preview news</b></p>
<p><?=$title;?></p>
<div>
<table style="flot:left; border : 1px solid #eee;">
<tbody>
<tr height="1"></tr>
<tr>
<td width="1"></td>
<td align="center">
<img height="200" width="225" align="left" src="<?=$target_temp_path1;?>" alt="">
<img height="200" width="225" align="left" src="<?=$linkupload;?>" alt="">
</td>
</tr>
<tr>
<td width="1"></td>
<td align="center"><font size="2" color="#333300"><?=$titleimg;?></font></td>
<td width="1"></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<span><?=$post;?></span>
<br />
<hr color="#0000FF" />
</div>
<?php
unset($target_temp_path1);
}
?>
<div style="display:block;">
<form enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<p>News title :
<input type="text" name="title" value="<?=$title;?>" size="40" /></p>
<p>Post :
<textarea name="post" rows="10" COLS="40" ><?=$post?></textarea></p>
<p>Image From PC :
<input type="file" name="fileupload" /></p>
<p>Image from link :
<input type="text" name="linkupload" value="<?=$linkupload;?>"/></p>
<p>Title of image :
<input type="text" name="titleimg" value="<?=$titleimg;?>"/></p>
<p>Title of image :
<input name="add" type="submit" value="Insert" />
<input name="prev" type="submit" value="Preview" /></p>
</form>
</div>
</body>
</html> |