2016-02-07 10 views
0

我已经修改了一个项目以将图像插入到图像中。它在本地服务器上完美工作,但在远程他说: 在此服务器上找不到请求的URL /覆盖03c7c0ace395d80182db07ae2c30f034.jpg。PHP |创建图像在本地服务器上工作,但不是远程主机

该脚本不创建图像,但在我的本地服务器上工作。 GD和Freefont安装,所以我不知道该怎么办 请帮我

<?php 
 

 
$fontname = './font/arial.ttf'; 
 
// controls the spacing between text 
 
$i=30; 
 
//JPG image quality 0-100 
 
$quality = 90; 
 

 
function create_image($user){ 
 

 
\t \t global $fontname; 
 
\t \t global $quality; 
 
\t \t $file = "./covers/".md5($user[0]['name'].$user[1]['name'].$user[2]['name']).".jpg"; 
 

 
\t // if the file already exists dont create it again just serve up the original 
 
\t //if (!file_exists($file)) { 
 

 

 
\t \t \t // define the base image that we lay our text on 
 
\t \t \t $im = imagecreatefromjpeg("pass.jpg"); 
 

 
\t \t \t // setup the text colours 
 
\t \t \t $color['grey'] = imagecolorallocate($im, 0, 0, 0); 
 
\t \t \t $color['green'] = imagecolorallocate($im, 55, 189, 102); 
 

 
\t \t \t // this defines the starting height for the text block 
 
\t \t \t $y = imagesy($im) - $height - 1393; 
 
\t \t \t $ye = imagesy($im) - $height - 1078; 
 

 
\t \t // loop through the array and write the text 
 
\t \t foreach ($user as $value){ 
 
\t \t \t // center the text in our image - returns the x value 
 
\t \t \t $x = 1260; 
 
\t \t \t $xe = 930; 
 
\t \t \t $text=$value['name']; 
 
\t \t \t $testo=$value['gatto']; 
 
\t \t \t $newtext = wordwrap($text, 40, "\n", true); 
 
\t \t \t imagettftext($im, $value['font-size'], 0, $x, $y, $color[$value['color']], $fontname,$newtext); 
 
\t \t \t $newtesto = wordwrap($testo, 40, "\n", true); 
 
\t \t \t imagettftext($im, $value['font-size'], 0, $xe, $ye, $color[$value['color']], $fontname,$newtesto); 
 
\t \t \t // add 32px to the line height for the next text block 
 

 

 
\t \t } 
 
\t \t \t // create the image 
 
\t \t \t imagejpeg($im, $file, $quality); 
 

 
\t //} 
 

 
\t \t return $file; 
 
} 
 

 
function center_text($string, $font_size){ 
 

 
\t \t \t global $fontname; 
 

 
\t \t \t $image_width = 800; 
 
\t \t \t $dimensions = imagettfbbox($font_size, 0, $fontname, $string); 
 

 
\t \t \t return ceil(($image_width - $dimensions[4])/2); 
 
} 
 

 

 

 
\t $user = array(
 

 
\t \t array(
 
\t \t \t 'name'=> '', 
 
\t \t \t 'font-size'=>'9', 
 
\t \t \t 'gatto'=>$_POST['gatto'], 
 
\t \t \t 'color'=>'grey'), 
 

 

 
\t \t array(
 
\t \t \t 'name'=> '', 
 
\t \t \t 'font-size'=>'16', 
 
\t \t \t 'color'=>'grey'), 
 

 
\t \t array(
 
\t \t \t 'name'=> '', 
 
\t \t \t 'font-size'=>'13', 
 
\t \t \t 'color'=>'green' 
 
\t \t \t) 
 

 
\t); 
 

 

 

 

 
\t $user = array(
 

 
\t \t array(
 
\t \t \t 'name'=> $_POST['name'], 
 
\t \t \t 'font-size'=>'9', 
 
\t \t \t 'gatto'=>$_POST['gatto'], 
 
\t \t \t 'color'=>'grey'), 
 

 

 
\t \t array(
 
\t \t \t 'name'=> $_POST['job'], 
 
\t \t \t 'font-size'=>'16', 
 
\t \t \t 'color'=>'grey'), 
 

 
\t \t array(
 
\t \t \t 'name'=> $_POST['email'], 
 
\t \t \t 'font-size'=>'13', 
 
\t \t \t 'color'=>'green' 
 
\t \t \t) 
 

 
\t); 
 

 

 

 

 

 
// run the script to create the image 
 
$filename = create_image($user); 
 

 
?> 
 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
 
<title>Schoolexploit.com | Modifica Etichette</title> 
 

 
<!-- Latest compiled and minified CSS --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 
 

 
<!-- Optional theme --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"> 
 
<link rel="stylesheet" href="./style.css" media="screen" title="no title" charset="utf-8"> 
 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
 

 
</head> 
 

 
<body> 
 

 
<div class="row"> 
 
\t <div class="col-xs-12" id="asd"> 
 
\t <img src="<?=$filename;?>" width="1000" height="500"/><br/><br/> 
 
\t </div> 
 

 
</div> 
 

 

 
<ul> 
 
<?php if(isset($error)){ 
 

 
\t foreach($error as $errors){ 
 

 
\t \t echo '<li>'.$errors.'</li>'; 
 

 
\t } 
 

 

 
}?> 
 
</ul> 
 
<div class="col-xs-12" id="asd"> 
 

 
<h2>Istruzioni:</h2> 
 

 
<p>Inserisci qui sotto il testo (rispetta il limite di caratteri)</p> 
 
<p>Clicca sul pulsante Modifica per generare l'etichetta</p> 
 
<p>Clicca col tasto destro sull'immagine, "salva immagine con nome..."</p> 
 
<p>Stampa e ritaglia l'etichetta (per un risultato ottimale è consigliata una stampante laser)</p> 
 
<p> \t Sostituiscila all'originale</p> 
 

 
<div class="dynamic-form"> 
 
<form action="" method="post"> 
 
<label>Testo1(Max 200):</label> 
 
<input type="text" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>" name="name" maxlength="200" placeholder=""><br/> 
 
<label>Testo2(Max 120):</label> 
 
<input type="text" value="<?php if(isset($_POST['gatto'])){echo $_POST['gatto'];}?>" name="gatto" maxlength="120" placeholder=""><br/> 
 
<input name="submit" type="submit" class="btn btn-primary" value="Modifica" /> 
 
</form> 
 
</div> 
 
</div> 
 

 

 

 

 
</body> 
 
</html>

+0

有你看着寻路,因为这可以在实际的服务器被指出错误,因为他们喜欢用全路径,而这相对的,而不是http:///但somthign,如:/ home/mysite.com/html/imgs等 –

+0

./?在服务器里面有一个www forder和一个html文件夹。我必须使用什么路径? –

+0

你会得到这个表单你的服务器控制面板等,可以运行一个phpinfo页面找到它,在这个http://stackoverflow.com/questions/6079479/how-to-get-the-absolute-path-to -the-public-html-folder –

回答

0

你检查的介绍目录的权限?将其设置为644或777.

我假设您在Windows上本地运行项目。 Windows处理权限与Linux不同。这就是为什么它在本地工作,但不在您的远程服务器上。

+0

我在数字海洋上运行。我如何设置777或644? –

+0

它的作品thanksssss !!!!!!!!!! –

0

他打我,但:

chmod("/file/or/directory", 0777); 

我忘了:如果你(你的网络服务器)没有对目录的写入权限。您无法直接chmod该目录,您需要从Shell获取Chown或chmod的所有权。

在Linux终端

sudo chmod 777 /some/directory 
相关问题