UPLOAD FILE TO DATABASE
<form method="post" action="" enctype="multipart/form-data">
Select file: <input type="file" name="f1">
<input type="submit" name="sub" value="UPLOAD">
</form>
<?php
if(is_uploaded_file($_FILES['f1']['tmp_name'])){
mysql_connect("localhost","root","");
mysql_select_db("test");
$cont = file_get_contents($_FILES['f1']['tmp_name']);
$cont = addslashes($cont);
if(mysql_query("insert tbl_images values ('','$cont')"))
echo "Image added";
else
echo "not";
}
?>
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts
Upload file to database
Sessions Login Logout
<?php
if(isset($_POST['sub'])){
$uname = $_POST['txtuname'];
$pwd = $_POST['txtpwd'];
if($uname=="scott" and $pwd=="scott123"){
session_start();
$_SESSION['aut'] = true;
echo "<script>location='welcome.php';</script>";
}
else{
echo "invalid";
}
}
?>
<form method="post" action="">
Username:<input type="text" name="txtuname">
Password:<input type="password" name="txtpwd">
<input type="submit" name="sub" value="login">
</form>
WELCOME.PHP
<?php
session_start();
if(isset($_SESSION['aut'])){
echo "Welcome to user";
}
else{
echo "<script>location='login.php';</script>";
}
?>
<a href="logout.php">Logout</a><link rel="canonical" href="">
LOGOUT.PHP
<?php
session_start();
session_destroy();
echo "Logout successful";
?>
File Upload in php
<form method="post" action="" enctype="multipart/form-data">
Select File: <input type="file" name="f1">
<input type="submit" name="sub" value="Upload">
</form>
<?php
if(is_uploaded_file($_FILES['f1']['tmp_name'])){
$fname = $_FILES['f1']['name'];
if(move_uploaded_file($_FILES['f1']['tmp_name'], "../testing/$fname"))
echo "File moved";
else
echo "File not moved";
}
else
echo "File not uploaded";
?>