我試圖在裁剪到一個目錄後保存裁剪後的圖像,但是當我點擊修剪按鈕時什麼也沒有發生。我從2天內陷入困境,請別人幫我解決。 我得到這些錯誤修剪後不保存到目錄中的圖像
Warning:imagecreatefromjpeg(public/image /)[function.imagecreatefromjpeg]:無法打開流:C:\ wamp \ www \ ModuleEx.com \ application \ modules中沒有這樣的文件或目錄\ admin \ controllers \ IndexController.php on line 64
警告:imagecreatefromjpeg(public/image /)[function.imagecreatefromjpeg]:無法打開流:C:\ wamp \ www \ ModuleEx中沒有這樣的文件或目錄。 com \ application \ modules \ admin \ controllers \ IndexController.php on line 64
Warning:imagejpeg()[function.imagejpeg]:無法打開'public/image/crop'進行寫入:權限被拒絕在C:\ WAMP \ WWW \ ModuleEx .COM \應用\模塊\管理員\控制器\ IndexController.php上線71
這是我的控制器代碼
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);
$this->view->file_obj=$file_obj;
}
}
}
}
}
這是我的PHTML代碼。
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$src = 'file_obj';
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,(int)$_POST['x'],(int)$_POST['y'],
$targ_w,$targ_h,(int)$_POST['w'],(int)$_POST['h']);
//header('Content-type: image/jpeg');
imagejpeg($dst_r,'file_obj',$jpeg_quality);
}
?>
<html>
<head>
<script src="public/js/jquery.min.js"></script>
<script src="public/js/jquery.Jcrop.js"></script>
<script src="public/js/jquery.color.js"></script>
<script type="text/javascript">
$(function(){
$('#cropbox').Jcrop({
aspectRatio: 1,
onSelect: updateCoords
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
</script>
<style type="text/css">
#target {
background-color: #ccc;
width: 500px;
height: 330px;
font-size: 24px;
display: block;
}
</style>
<?=$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="" onsubmit="">
<input type="file" name="file" />
<input type="submit" name="submit" value="Upload"/><br/></br>
<img id="cropbox" src="<?php echo $this->file_obj?>" alt="Image" style="display: block; visibility: visible; width: 602px; height: 400px; border: medium none; opacity: 0.5;"/><br/>
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" value="Crop Image" class="btn btn-large btn-inverse" />
</form>
</body>
</html>
這是圖像目錄路徑C:\ WAMP \ WWW \ ModuleEx.com \ PUBLIC \圖像 – Tuhin
,這是控制路徑C:\ WAMP \ WWW \ ModuleEx.com \應用\ modules \ admin \ controllers – Tuhin
嘗試製作一個公共/圖像文件夾以及您的IndexController.php目錄。您的系統/程序將在此代碼中搜索public/image以及indexController.php: $ file_obj =「public/image /".$ file_name; – Aljie