Showing posts with label upload. Show all posts
Showing posts with label upload. Show all posts

Thursday, 2 July 2015

Upload CSV file in php

Upload CSV file

             $File_Name=$_FILES['upload']['tmp_name'];

                $fp=fopen($File_Name,'r');

                while($data=fgetcsv($fp))
                {
                    $add_data=array('Name'=>$data[0],'No_of_Nights'=>$data[1])

                 }

Monday, 2 September 2013

display image in registration form

//Display Image in Registration Form

//image_form.php

<html>
<body>
<fieldset>
<legend>Customer Details</legend>
<form action="action.php" enctype="multipart/form-data"
method="post">
<table>
<tr>
<td><label>Name:</label></td>
<td><input name="name" type="text" /></td>
</tr>
<tr>
<td><label>Phone No:</label></td>
<td><input name="phone" type="text" id="phone" /></td>
</tr>
<tr>
<td><label>Email Id:</label></td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><input name="address" type="text" id="address" /></td>
</tr>
<tr>
<td><label>Country:</label></td>
<td><input name="con" type="text" id="con" /></td>
</tr>
<tr>
<td><label>Select your photo:</label></td>
<td><input name="image" type="file" /></td>
</tr>
<tr>
<td><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>

//...............................................................................................................................................
//Action.php

<html>
<body>
<?php
 $sname=$_POST['name'];
 $phone=$_POST['phone'];
 $email=$_POST['email'];
 $address=$_POST['address'];
 $contry=$_POST['con'];
 extract($_FILES['image']);
 /*print_r($_FILES);*/
 if($error==0)
 {
   if(($type="image/jpeg")||$type="image/pjpeg")
   {
    if(($size)/1024<=1000)
    {
     $path="upload";
     $filename=rand(1,1000)."_".$name;
     $act_path=$path."/".$filename;
     copy($tmp_name,$act_path);
     $f=1;
    }
    else
    {
     $msz="its too large! i can't handle it.";
    }
   }
   else
   {
    $msz="Opps! your file is not valid";
   }
 }
else
{
$msz="Error in the file!!";
}
if($f==1)
{
?>
<div style="width:550px;margin:0 auto;
padding:10px;background-color:#69F;
height:130px;box-shadow:#000 0 0 10px;">
<div style="float:right;border:1px solid #ccc;
padding:1px 2px;width:130px;
box-shadow:#aaa 0 0 10px;">
<?php
echo "<img src=\"$act_path\" height=100/>";
?>
</div>
<div style="float:left;padding-right:5px;">
<table style="text-align:left;color:#ffffff;
font-weight:bold;text-shadow:1px 1px #aaa;">
<tr>
<td>Name:</td>
<td style="text-align:left;color:yellow;">
<?php echo $sname; ?></td>
</tr>
<tr>
<td>Phone No:</td>
<td style="text-align:left;color:yellow;">
<?php echo $phone; ?></td>
</tr>
<tr>
<td>Email Id:</td>
<td style="text-align:left;color:yellow;">
<?php echo $email; ?></td>
</tr>
<tr>
<td>Address:</td>
<td style="text-align:left;color:yellow;">
<?php echo $address; ?></td>
</tr>
<tr>
<td>Country:</td>
<td style="text-align:left;color:yellow;">
<?php echo $contry; ?></td>
</tr>
</table>
</div>
</div>
<?php
}
else
{
header("location:image_form.php?data=$msz");
}
?>
</body>

</html>

upload file or image into database in php mysql

//Upload file or image into database in php(up1)
//create table as follows..........

<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td>please select a file</td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
value="16000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile'])));
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('bnr1', $con);
if($db){
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
}
?>
end