I am new in php.I am Uploading a file from local to remote server but file is not uploading .I am uploading pdf file from server php which is in Dreamweaver but file is not uploaded what to do..And next thing i dont want extension .pdf i wants only name of pdf.. ?
if(isset($_POST['submit']))
{
echo"Upload Only PDf File";
$fileName=$_FILES["filepdf"]["name"];
$fileSize=$_FILES["filepdf"]["size"]/2024;
$fileType=$_FILES["filepdf"]["type"];
$fileTmpName=$_FILES["filepdf"]["tmp_name"];
if($fileType=="application/pdf")
{
if($fileSize<=200)
{
$random=rand(1111,9999);
$newFileName=$random.$fileName;
$uploadPath="testUpload/".$newFileName;
if(move_uploaded_file($fileTmpName,$uploadPath))
{
echo "Successful<BR>";
echo "File Name :".$newFileName."<BR>";
echo "File Size :".$fileSize." kb"."<BR>";
echo "File Type :".$fileType."<BR>";
}
else
{
echo "Maximum upload file size limit is 200 kb";
}
}
else
{
return false;
echo "You can only upload a pdf file.";
}
<form method="post" enctype="multipart/form-data" name="myform" >
<br/>
<label>Select Category:</label>
<div class="form-group">
<?php
include('config.php');
$query1=mysql_query("select catnm from category");
?>
<select class=form-control m-b-10 name=catnm id=catnm >
<?php
echo"<option>---Select---</option>";
while($query=mysql_fetch_array($query1))
{
$selectedCat = '';
if($query[catnm] == $query4['catnm'])
{
$selectedCat = "selected";
}
echo "<option value='$query[catnm]' $selectedCat >$query[catnm]</option>";
}
?>
</select>
<br/>
<input type="text" class="form-control" id="prodnm" placeholder="Product
Name" name="prodnm" required value="<?php if(isset($query4['prodnm'])){
echo $query4['prodnm'];}?> "/>
</div>
<div class="form-group">
<textarea class="form-control" id="catdtl" name="prod_dtl"
placeholder="Product Detail" "rows="10" cols="62" required><?php
if(isset($query4['prod_dtl'])){echo $query4['prod_dtl'];} ?></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">PDF File</label>
<input type="file" id="exampleInputFile" accept="application/pdf"
name="filepdf" >
file : <?php if(isset($query4['pdf'])){
echo $query4['pdf'];} ?>
</div>
<div class="checkbox">
<label>
<input id="checkbox" type="checkbox" name="updates"
<?php if(isset($query4['downld'])) { if($query4['downld'] == 'Yes') echo
"checked='checked'"; echo $query4['downld'];}
?> />Is Downloadable <br />
</label>
</div>
<input type="text" placeholder="Date of Upload" name="date" value="<?php
if(isset($_GET['id'])){$id = $_GET['id'];echo $query4['date'];
}
else
{
echodate('d/m/Y');
}? >"id="datepicker-7">
<div style="padding-top:20px;padding-bottom:40px;width:650px;">
<input type="submit" name="submit" id="button"
onclick="madeSelection(document.getElementById('catnm'),'Please Select`
Category',event)" value="<?php if(isset($_GET['id'])){$id =
$_GET['id'];echo"Update";}else{echo"Submit";}?>"/>
<input type="button" value="cancel" onclick="window.location='index.php'"/>
Related
Here i have numerous input fields in a form, which are working perfectly. And now, i want to add new input boxes and their labels according to property_type , Which is already exist on this page.
Now, Kindly Suggest me How can i add new fields in that form.
Here is my Form Code
<div class="dashboard_price_left">
<h3>
<?php
if ($this->lang->line('BasePrice') != '') {
echo stripslashes($this->lang->line('BasePrice'));
} else
echo "Base Price";
?>
</h3>
<p>
<?php
if ($this->lang->line('Atitleandsummary') != '') {
echo stripslashes($this->lang->line('Atitleandsummary'));
} else
echo "Set weekly or monthly price guests will see for your listing.";
?>
</p>
</div>
<?php
if ($listDetail->row()->home_type == 'Office') {
} else if ($listDetail->row()->home_type == 'House') {
}
?>
<form id="pricelist" name="pricelist" action="site/product/savePriceList" method="post">
<div class="dashboard_price_right">
<label><?php
if ($this->lang->line('Pernight') != '') {
echo stripslashes($this->lang->line('Pernight'));
} else
echo "Per night";
?>
</label>
<div class="amoutnt-container">
<?php if ($currentCurrency == '') { ?>
<span class="WebRupee"><?php echo $currencyDetail->row()->currency_symbols; ?></span>
<?php } else { ?>
<span class="WebRupee"><?php echo $currentCurrency; ?></span>
<?php } ?>
<input type="text" id="price" value="<?php
if ($listDetail->row()->price != '0.00') {
echo intval($listDetail->row()->price);
}
?>" class="per_amount_scroll" name="price" onkeypress="return onlyNumbersWithDot(event);" onchange="javascript:Detailview(this,<?php echo $listDetail->row()->id; ?>, 'price');" />
<input type="hidden" id="id" name="id" value="<?php echo $listDetail->row()->id; ?>" />
</div>
<div class="dashboard_currency">
<label><?php
if ($this->lang->line('Currency') != '') {
echo stripslashes($this->lang->line('Currency'));
} else
echo "Currency";
?>
</label>
<div class="select select-large select-block">
<select name="currency" id="currency" onchange="javascript:Detailview(this,<?php echo $listDetail->row()->id; ?>, 'currency');get_currency_symbol(this)" >
<!--<option value="">select</option>-->
<?php foreach ($currencyDetail->result() as $currency) { ?>
<option value="<?php echo $currency->currency_type; ?>" <?php if ($listDetail->row()->currency == $currency->currency_type) echo 'selected="selected"'; ?>><?php echo $currency->currency_type; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</form>
Here is a pic of my Property prices form
Note: There are two types of property that are following:
1. Office
2. House
on the basis of these property, I want to add more fields in my form.
Please suggest me, Thanks in Advance :)
you can change it base on conditon and pass hidden field which indicates you office or house.
<?php
if ($listDetail->row()->home_type == 'Office')
{
<input type="hidden" name="home_type" value="Office" />
<input type="text" name="per_day" value="" />
<input type="text" name="half_day" value="" />
<input type="text" name="per_hour" value="" />
}
else if ($listDetail->row()->home_type == 'House')
{
<input type="hidden" name="home_type" value="House" />
<input type="text" name="per_night" value="" />
<input type="text" name="per_day" value="" />
<input type="text" name="per_hour" value="" />
}
?>
How to Insert and update using one form in php. Insert and Update not working
what to do. I have file productinsert.php and one file for display data displayProduct.php when i am inserting data are not inserted and it redirect on same page it not displaying data on addProduct.php also not updating plz help
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<?php
include('header1.php');
?>
</head>
<body>
<?php
include('sidenav.php');
?>
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h2>Add Product</h2>
</div>
</div>
<!-- /. ROW -->
<hr />
<div class="row">
<?php
include('config.php');
if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_POST['submit']))
{
$fileName=$_FILES["filepdf"]["name"];
$fileSize=$_FILES["filepdf"]["size"]/2024;
$fileType=$_FILES["filepdf"]["type"];
$fileTmpName=$_FILES["filepdf"]["tmp_name"];
if($fileType=="application/pdf"){
if($fileSize<=200){
//New file name
$random=rand(1111,9999);
$newFileName=$random.$fileName;
//File upload path
$uploadPath="testUpload/".$newFileName;
//function for upload file
if(move_uploaded_file($fileTmpName,$uploadPath))
{
echo "Successful<BR>";
echo "File Name :".$newFileName."<BR>";
echo "File Size :".$fileSize." kb"."<BR>";
echo "File Type :".$fileType."<BR>";
}
else
{
echo "Maximum upload file size limit is 200 kb";
}
}
else
{
return false;
echo "You can only upload a pdf doc file.";
}
echo "here downld";
$updates = isset($_POST['updates']) ? 'Yes' : 'No';
$catnm=$_POST['catnm'];
$prodnm=$_POST['prodnm'];
$prod_dtl=$_POST['prod_dtl'];
//$updates=$_POST['downld'];
$date=$_POST['date'];
$query=("insert into addproduct(catnm,prodnm,prod_dtl,pdf,downld,date)
values('$catnm','$prodnm','$prod_dtl','$uploadPath','$updates','$date')");
$result = mysql_query($query,$conn);
echo"record inserted";
if($result)
{
header("location:addProduct.php");
}
}
}
}
else if($_SERVER['REQUEST_METHOD']=='GET')
{
if(isset($_GET['id']))
{
$id = $_GET['id'];
if(isset($_POST['submit']))
{
$updates['downld'] = isset($_POST['downld']) ? 'Yes' : 'No';
$cat['catnm']=$_POST['catnm'];
$prodnm['prodnm']=$_POST['prodnm'];
$prod_dtl['prod_dtl']=$_GET['prod_dtl'];
$pdf['pdf']=$_GET['pdf'];
$downld['downld']=$_GET['downld'];
$date['date']=$_GET['date'];
$query3=mysql_query("update addproduct set catnm='$cat',
prodnm='$prodnm',prod_dtl='$prod_dtl'
,pdf='$pdf',downld='$updates',date='$date' where id='$id'");
if($query3)
{
header('location:addProduct.php');
}
}
$query1=mysql_query("select * from addproduct where id='$id'");
$query4=mysql_fetch_array($query1);
//echo "<pre>";
//print_r($query4);
}
}
?>
<div class="col-md-6 col-sm-12 col-xs-12">
<div class="panel-body">
<form role="form" method="get" enctype="multipart/form-data"
name="myform" action= "<?php echo $_SERVER['PHP_SELF'];?>">
<br/>
<label>Select Category:</label>
<div class="form-group">
<?php
include('config.php');
$query1=mysql_query("select catnm from addcategory");
?>
<select class=form-control m-b-10 name=catnm id=catnm >
<?php
echo"<option>---Select---</option required>";
while($query=mysql_fetch_array($query1))
{
$selectedCat = '';
if($query[catnm] == $query4['catnm'])
{
$selectedCat = "selected";
}
echo "<option value='$query[catnm]' $selectedCat >$query[catnm]</option>";
}
?>
</select>
<br/>
<div class="form-group">
<input type="text" class="form-control" id="prodnm"
placeholder="Product Name" name="prodnm" required
value= "<?php $query4['prodnm']; ?>"/>
</div>
<div class="form-group">
<textarea class="form-control" id="catdtl" name="catdtl"
placeholder="Product Detail" "rows="10" cols="62" required>
<?php echo $query4['prod_dtl']; ?>
</textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">PDF File</label>
<input type="file"
id="exampleInputFile" accept="application/pdf" name="filepdf" required >
file : <?php echo $query4['pdf']; ?>
</div>
<div class="checkbox">
<label>
<input id="checkbox" type="checkbox" name="updates" required
/> Is Downloadable <br />
</label>
</div>
<input type="text"
placeholder="Date of Upload" id="" name="date" required />
<div style="padding-top:20px;padding-bottom:40px;width:650px;">
<input type="submit" name="submit" id="button" tabindex="2"/>
<hr/>
</form>
<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['submit']))
{
$updates['downld'] = isset($_POST['downld']) ? 'Yes' : 'No';
$cat['catnm']=$_POST['catnm'];
$prodnm['prodnm']=$_POST['prodnm'];
$prod_dtl['prod_dtl']=$_GET['prod_dtl'];
$pdf['pdf']=$_GET['pdf'];
$downld['downld']=$_GET['downld'];
$date['date']=$_GET['date'];
$query3=mysql_query("update addproduct set catnm='$cat',
prodnm='$prodnm',prod_dtl='$prod_dtl'
,pdf='$pdf',downld='$updates',date='$date' where id='$id'");
if($query3)
{
header('location:addProduct.php');
}
}
}
?>
</div>
<!-- /. ROW -->
</div>
<!-- /. PAGE INNER -->
</div>
<!-- /. PAGE WRAPPER -->
</div>
</body>
</html>
When is need to update add to form a hidden filed with id equal to row to update and name id. If need to insert don't use id row.
<form>
if(isset($_GET['update'])) echo '<input type="hidden" name="id" value="'.$_GET['id'].'">';
</form>
if(isset($_POST['id'])) { do sql to update where id=$_POST['id']; } else {do sql to insert}
Also to update you need to fill inputs with existing data from DB like this
<input value="<? if(isset($_GET['update'])) echo $value; ?>">
<select> <option value="1" if(isset($_GET['update']) && select1==1) echo 'selected'; >1</options>
<option value="2" if(isset($_GET['update']) && select1==2) echo 'selected'; >2</options>
I'm trying to change to color of the error alerts on this php file. By my css files doesn't seems to respond. Can you help me figure out the reason? I'd like to make my alerts blue and bigger.
Here's the form :
<div id="dv_global_form">
<form action="index.php" method="post">
<p class="required">Required fields *</p>
Name:<input type="text" name="name" <?php echo"value='$nameValue'"?>> <span class="required"> *</span><?php echo"<span class='required'> $nameErr</span>" ;?></span><br>
Surname:<input type="text" name="surname"<?php echo"value=$surnameValue"?>><span class="required"> *</span><?php echo"<span class='required'> $surnameErr</span>" ;?></span><br>
Date of Birth:<select name="dob">
<?php dob()?>
</select><span class="required"> *</span><?php echo"<span class='required'> $dobErr</span>" ;?><br>
Email:<input type="email" name="email" <?php echo"value=$emailValue"?>><span class="required"> *</span><?php echo"<span class='required'> $emailErr</span>" ;?>
<h3>Gender<span class="required"> * </span></h3>
<input type="radio" name="gender" value="male">Male<br>
<input type="radio" name="gender" value="female">Female<br>
<input type="submit" value="submit">
</form>
<?php echo"<p class='required' > $genderErr</p>" ;?>
</div>
Here's the php file containing the functions:
function dob(){
echo "<option></option>";
for($i=1989;$i<2001;$i++){
if($i==$_POST['dob']){
echo "<option selected='selected'>$_POST[dob]</option>";
}else{
echo "<option>$i</option>";
}
}
}
// Validate fields
$nameErr= $surnamErr=$emailErr= $dobErr=$sexErr=$genderErr="";
$nameValue=$surnameValue=$dobValue=$emailValue="";
if($_SERVER["REQUEST_METHOD"]==POST){
if(empty($_POST['name'])){
$nameErr="Name is required field";
}else{
if(!preg_match("/^[a-zA-Z\s]*$/",$_POST['name'])){
$nameErr="Only letters and white space allowed";
}else{
$nameValue=$_POST['name'];
}
}
if(empty($_POST['surname'])){
$surnameErr="Surname is required field";
}else{
if(!preg_match("/^[a-zAZ]*$/",$_POST['surname'])){
$surnameErr="Only letters and white space allowed";
}else{
$surnameValue=$_POST['surname'];
}
}
if(empty($_POST['dob'])){
$dobErr="Date of birth is required field";
}
if(empty($_POST['email'])){
$emailErr="Email is a required filed";
}else{
if(!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
$emailErr="This email format is not valid";
}
$emailValue=$_POST['email'];
}
if(empty($_POST['gender'])){
$genderErr="Gender is a required field";
}else{
}
}
And here's the css :
.required{
color:blue;
}
#gender{
color:blue;
}
So in BulletProof's documentation, I follow what I had to do and the image doesn't even get to "echo" phase #2.
https://github.com/samayo/bulletproof/blob/master/README.md
if (isset($_POST['post_blog_submit'])) {
$image = new Bulletproof\Image($_FILES);
$title = $filter->input("string", $_POST['title']);
$body = $filter->input("string", $_POST['body']);
$image->setName('test')
->setMime(array('jpg'))
->setLocation('/data/gallery', 777)
->setDimension(250, 250)
->setSize(100, 10000000);
if($image['bthumb']){
echo 'Phase #2';
if($image->upload()){
echo $image->getName(); // samayo
echo $image->getMime(); // gif
echo $image->getLocation(); // avatars
echo $image->getFullPath(); // avatars/samayo.gif
echo 'uploaded';
} else {
echo $image['error'];
}
}
echo $image['error'];
}
This is my PHP code, which does exactly what README.MD stated for me to do.
<form name="post_blog" method="post" enctype="multipart/form-data">
<label for="title">Blog Title</label>
<input class="form-control" type="text" name="title" placeholder="Blog Title" required /> <br/>
<label for="body">Blog Body</label>
<textarea class="form-control" name="body" placeholder="Place your text ..." required> </textarea> <br/>
<label for="bthumb">Blog Thumbnail</label>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
<input type="file" name="bthumb" /> <br/>
<div class="pull-right">
<input type="hidden" name="post_blog_submit" value="1" />
<input type="submit" class="btn btn-danger" value="Submit!" />
</div>
</form>
I don't know what is possibly wrong, the form part of it looks correct and the backend looks correct. But it isn't even detecting the input itself.
I'm creating a web app in Codeigniter. Here's the code in VIEW's.
<div class="bold light-gray">Add a photo or two!</div>
<p class="short">Or three, or more! Prospective Buyers love photos that highlight the features of your parts or gear.</p>
<form class="ajaxform" method="post" enctype="multipart/form-data" action='<?php echo site_url('UploadImage/upload_Image');?>'>
<input type="hidden" name="do" value="upload"/>
Upload your image <input type="file" name="Filedata" id="photo" onChange="abc()" />
<input type="hidden" name="timestamp" value="<?php echo $timestamp;?>" />
<input type="hidden" name="token" value="<?php echo md5('unique_salt' . $timestamp);?>" />
<input type="hidden" name="customer_id" value="<?php echo $customer['id'];?>" />
</form>
</div>
<!-- /.box.center -->
<?php echo form_open('/secure/add_item/'.$id, array('id'=>'listitem') ); ?>
<div id="img_cant"> <?php
if(isset($images) && !empty($images)) {
foreach($images as $key=>$img){
?>
<input type="hidden" value="<?php echo $img; ?>" name="images[]" id="hid_<?php echo $key; ?>">
<?php
}
}
?>
</div>
I want to allow the user to just add 3 or 4 images maximum. How to do that?
<?php $count=count($_FILES['name']);
if($count>3)
{
echo "Your error message";
}
else{
echo "your desired activity";
}?>
Using jquery you can call this function while submit your form
var file_nu = $("input:file")[0].files.length;
if(file_nu >3)//apply your condition here
{
return FALSE;
}else{
return TRUE;
}