Fiqhi Posted February 28, 2014 Share Posted February 28, 2014 i have input file type button <input type="hidden" id="id" name="id" value="'.$id.'" /><input type="hidden" id="old_logo" name="old_logo" value="'.$setuser[cmp_image].'" /> <div class="text1">Company Logo:</div> <div class="text2"><input name="cmp_image" id="cmp_image" size="25" type="file" class="btn_style"> This is the upload image function if ((($_FILES["cmp_image"]["type"] == "image/gif") || ($_FILES["cmp_image"]["type"] == "image/jpeg") || ($_FILES["cmp_image"]["type"] == "image/png") )) { if($old_logo!='') unlink('company_image/'.$old_logo); $namafile=$_SESSION['uid']."_cp_".$_FILES["cmp_image"]["name"]; move_uploaded_file($_FILES["cmp_image"]["tmp_name"], "company_image/".$namafile); $addfile="cmp_image='".$namafile."',"; } And im using this to show the logo if ($setuser[cmp_image]!='') { $pictinfo='<img src="company_image/'.$setuser[cmp_image].'" alt="No Photo" height="50" width="100"> '; }else{ $pictinfo='<img src="images/icon_no_company.png" alt="No Logo" height="50" width="100">'; } The upload button works correctly, but it didn't reflect that the file has been uploaded. $setuser[cmp_image] always return null ($setuser[cmp_image] == ' ') Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/ Share on other sites More sharing options...
Ch0cu3r Posted February 28, 2014 Share Posted February 28, 2014 How is the $setuser array defined? Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1471050 Share on other sites More sharing options...
Fiqhi Posted February 28, 2014 Author Share Posted February 28, 2014 $setuser=$rwiclas->viewone('company',' where id="'.$id.'" and uid="'.$iduser.'"'); $rwiclas=new rwi($db); Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1471054 Share on other sites More sharing options...
Fiqhi Posted February 28, 2014 Author Share Posted February 28, 2014 Sorry forgot this function viewone($tabel,$tambah='') { $sql="select * from ".$tabel. " " .$tambah; $res=$this->db->Execute($sql); return $res->fields; } Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1471058 Share on other sites More sharing options...
Ch0cu3r Posted February 28, 2014 Share Posted February 28, 2014 So how is the company image added to the cmp_image field in your database? Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1471069 Share on other sites More sharing options...
Fiqhi Posted February 28, 2014 Author Share Posted February 28, 2014 if ((($_FILES["cmp_image"]["type"] == "image/gif") || ($_FILES["cmp_image"]["type"] == "image/jpeg") || ($_FILES["cmp_image"]["type"] == "image/png") )) { if($old_logo!='') unlink('company_image/'.$old_logo); $namafile=$_SESSION['uid']."_cp_".$_FILES["cmp_image"]["name"]; move_uploaded_file($_FILES["cmp_image"]["tmp_name"], "company_image/".$namafile); $addfile="cmp_image='".$namafile."',"; } if ($id==''){ $sql="insert into company set uid='".$iduser."', ".$addfile." cmp_name='".strip_tags($cmp_name)."', cmp_desc='".strip_tags($cmp_desc)."', cmp_email='".strip_tags($cmp_email)."', cmp_date=now()"; $msg="<font color=green>Company has been created successfully</font>"; }else{ $sql="update company set ".$addfile." cmp_name='".strip_tags($cmp_name)."', cmp_desc='".strip_tags($cmp_desc)."', cmp_email='".strip_tags($cmp_email)."' where id='".$id."' and uid='".$iduser."'"; $msg="<font color=green>Company has been edited successfully</font>"; } Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1471070 Share on other sites More sharing options...
Fiqhi Posted March 1, 2014 Author Share Posted March 1, 2014 nvm Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1471118 Share on other sites More sharing options...
VijayaGanapathy Posted March 21, 2014 Share Posted March 21, 2014 Check whether you have enctype="multipart/form-data" attribute inside form tag Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1473419 Share on other sites More sharing options...
masters Posted March 26, 2014 Share Posted March 26, 2014 Working code for upload photo files: <? session_start(); if (empty($_FILES["cmp_image"]["name"])) $_FILES["cmp_image"]["name"] = ""; if (empty($_FILES["cmp_image"]["type"])) $_FILES["cmp_image"]["type"] = ""; if (empty($old_logo)) $old_logo = ""; if (empty($setuser["cmp_image"])) $setuser["cmp_image"] = ""; ?> <form action="#" method="post" enctype="multipart/form-data"> <input type="file" name="cmp_image"><br/> <input type="submit" value="Upload"> </form> <? //upload if ((($_FILES["cmp_image"]["type"] == "image/gif") or ($_FILES["cmp_image"]["type"] == "image/jpeg") or ($_FILES["cmp_image"]["type"] == "image/png") )) { if($old_logo!='') unlink(''.$old_logo); $namefile=session_id()."_cp_".$_FILES["cmp_image"]["name"]; move_uploaded_file($_FILES["cmp_image"]["tmp_name"], "".$namefile); $addfile="cmp_image='".$namefile."',"; } echo 'file name on your PC is "' . $_FILES["cmp_image"]["name"] . '"'; echo '<br/>'; echo 'file name on our SERVER is "' . session_id()."_cp_".$_FILES["cmp_image"]["name"] . '"'; echo '<br/>'; // show if ($_FILES["cmp_image"]["name"]!='') { $pictinfo='<img src="'.session_id()."_cp_".$_FILES["cmp_image"]["name"].'" alt="No Photo" height="50" width="100">'; echo $pictinfo; ; } else { $pictinfo='<img src="company.jpg" alt="No Logo" height="50" width="100">'; echo $pictinfo; }; ?> This code is working. Link to comment https://forums.phpfreaks.com/topic/286608-input-file-button-didnt-working/#findComment-1473924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.