您好我是zend的新手,我正在尝试上传图片并将其显示为裁剪。图像在ftp上正确上传并保存到文件夹中,但上传后它没有出现。请帮助我。
我的控制器代码。
public function indexAction()
{
if(isset($_FILES['file']['name'])){ //user upload file
$file_name = stripslashes($_FILES['file']['name']);
$ext_idx = strrpos($file_name,".");
if(!$ext_idx) //hide this if ur app can upload without ext
echo "File invalid.";
else{
$ext_length = strlen($file_name) - $ext_idx;
$extension = strtolower(substr($file_name,$ext_idx+1,$ext_length));
//allowed extension
$ext_list = array("pdf", "doc","jpg", "jpeg", "gif", "png");
if(!in_array($extension, $ext_list))
echo "System can't support your extension.";
else{
$size = (2500 * 1024); //2500 Kb
$file_size=filesize($_FILES['file']['tmp_name']);
if($file_size > $size)
echo "File is oversize. Max 2500 Kb.";
else{
//change name
$file_name = rand(10,1000).".".$extension;
$file_obj="public/image/".$file_name;
$copied = copy($_FILES['file']['tmp_name'], $file_obj);
if(!$copied)
echo "Failed.";
else
{
$file_data = array( 'file_name' => $file_name );
}
}
}
}
}
我的phtml代码 jQuery的(函数($){
var api;
$('#target').Jcrop({
// start off with jcrop-light class
bgOpacity: 0.5,
bgColor: 'white',
addClass: 'jcrop-light'
},function(){
api = this;
api.setSelect([130,65,130+350,65+285]);
api.setOptions({ bgFade: true });
api.ui.selection.addClass('jcrop-selection');
});
});
</script>
<?=$this->headLink()->appendStylesheet('/public/css/demos.css');?>
<?=$this->headLink()->appendStylesheet('/public/css/main.css');?>
<?=$this->headLink()->appendStylesheet('/public/css/jquery.Jcrop.min.css');?>
</head>
<body>
<form id="file_form" method="POST" enctype="multipart/form-data" action="">
<input type="file" name="file" />
<input type="submit" name="submit" value="Upload"/><br/></br>
<img id="target" src="<?php echo SITE_URL ?>public/image/.'$file_obj'" alt="Image" style="display: block; visibility: visible; width: 602px; height: 400px; border: medium none; opacity: 0.5;"/><br/>
</form>
</body>