image upload works on localhost but not online
image upload works on localhost but not online
I know that this question has been answered many times, but i still have trouble uploading images..
Image upload works fine on localhost, but doesn't work on remote server(linux)
I have already tried solutions related this question. And I also tried permissions to change on 777 and 755 but still it was not working.
But it still doesn't work.
Thanks For any Help.
//==================== Insert Section ========================
$tablename='tbl_slider';
if(isset($_REQUEST['submit']) && $_REQUEST['submit']=='Submit')
{
$heading=$_REQUEST['heading'];
$content = $_REQUEST['content'];
$data = array(
'heading' => $heading,
'content' => $content
);
$lastid=$obj->insert($tablename,$data);
if($lastid>0)
{
$uploadpath='../upload/slider/';
$img=$obj->ImageUpload('image',$uploadpath,'img-');
if(!empty($img))
{
$data['image']=$img['name'];
$result=$obj->update($tablename,$data,"id='".$lastid."'");
@unlink($uploadpath.$previous_pic);
}
$msg='<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<strong> <i class="icon fa fa-check"></i>Success!</strong>
Product Added Successfully..!
</div>';
}
else
{
$msg='<div class="alert alert-danger alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<strong> <i class="icon fa fa-check"></i>Warning!</strong>
An Unexpected Error.
</div>';
}
}
//============= Function For Image Uploading ==============
function ImageUpload($fieldname,$uploadpath,$pfx)
{
if(count($_FILES[$fieldname]['name'])>0)
{
if (!mkdir($uploadpath))
{
mkdir($uploadpath,077,true);
}
$targetpath = $uploadpath;
$ext=$_FILES[$fieldname]['name'];
$ext=explode(".",$ext);
if($ext[1]=="jpg" || $ext[1]=="jpeg" || $ext[1]=="png" || $ext[1]=="PNG" || $ext[1]=="JPEG" || $ext[1]=="JPG")
{
if($_FILES[$fieldname]['size'] <= 2000000) // 2MB
{
$filename=$targetpath.$pfx.time().".".$ext[1];
$name=end(explode('/',$filename));
if(move_uploaded_file($_FILES[$fieldname]['tmp_name'],$filename))
{
return array('source'=>$filename,'name'=>$name);
}
}
}
else
{
//echo "Please Choose Image Format";
}
}
}
//=============== Insert Into Datebase==========================
public function insert($table=null,$array_of_values=array())
{
if ($table===null || empty($array_of_values) || !is_array($array_of_values)) return false;
$fields=array(); $values=array();
foreach ($array_of_values as $id => $value) {
$fields=$id;
if (is_array($value) && !empty($value[0])) $values=$value[0];
else $values="'".$value."'";
}
$s = "INSERT INTO $table (".implode(',',$fields).') VALUES ('.implode(',',$values).')';
if ($this->con->query($s)) return $this->con->lastInsertId();
return false;
}
077
mkdir($uploadpath,077,true);
of course sir, and it is working on localhost, but i also tried permissions 777 and 755 but result was same there.
– BALAWANT MAURYA
Jun 29 at 13:09
This sounds like a permissions issue. Working on
localhost is often dependent on the user your http process is running under. Is the directory being created? Do you have the same issue if you create the directory in advance?– Mr Glass
Jun 29 at 13:21
localhost
http
2 Answers
2
You can follow these steps to fix the issue:
error_log
if
if($lastid>0)
$_FILES['userfile']['error']
phpinfo()
ini
upload_max_filesize
post_max_size
max_input_time
i checked all the things. Now i can update data with the image but can not upload still.Even by inserting manually in database i can update an image from admin pannel of the website but unable to upload from admin pannel.
– BALAWANT MAURYA
Jun 30 at 6:30
There are directory permission issue.
give permission to the upload folder
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you sure
077is the permissions you want inmkdir($uploadpath,077,true);?– Mr Glass
Jun 29 at 11:29