Jump to content

Input file button didn't working


Fiqhi

Recommended Posts

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
Share on other sites


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
Share on other sites

  • 3 weeks later...

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.