我知道这个问题已经回答了很多次,但是上传图片还是有困难。
图像上传在localhost上工作正常,但在远程服务器(linux)上不工作
我已经尝试过与该问题有关的解决方案。而且我还尝试了更改777和755的权限,但仍然无法正常工作。
但是它仍然不起作用。
感谢您的帮助。
//==================== 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;
}
答案 0 :(得分:0)
您可以按照以下步骤解决此问题:
error_log
if
:if($lastid>0)
$_FILES['userfile']['error']
phpinfo()
,ini
设置:upload_max_filesize
,post_max_size
,
max_input_time
答案 1 :(得分:0)
存在目录权限问题。
give permission to the upload folder