菲律宾比索 |创建映像适用于本地服务器,但不适用于远程主机


PHP | Create image works on local server but not remote host

我修改了一个项目,将文本插入图像中。它在本地服务器上完美运行,但在远程服务器上他说:在此服务器上找不到请求的 URL/covers/03c7c0ace395d80182db07ae2c30f034.jpg。

该脚本不会创建映像,但在我的本地服务器上它可以工作。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){
		global $fontname;
		global $quality;
		$file = "./covers/".md5($user[0]['name'].$user[1]['name'].$user[2]['name']).".jpg";
	// if the file already exists dont create it again just serve up the original
	//if (!file_exists($file)) {
			// define the base image that we lay our text on
			$im = imagecreatefromjpeg("pass.jpg");
			// setup the text colours
			$color['grey'] = imagecolorallocate($im, 0, 0, 0);
			$color['green'] = imagecolorallocate($im, 55, 189, 102);
			// this defines the starting height for the text block
			$y = imagesy($im) - $height - 1393;
			$ye = imagesy($im) - $height - 1078;
		// loop through the array and write the text
		foreach ($user as $value){
			// center the text in our image - returns the x value
			$x = 1260;
			$xe = 930;
			$text=$value['name'];
			$testo=$value['gatto'];
			$newtext = wordwrap($text, 40, "'n", true);
			imagettftext($im, $value['font-size'], 0, $x, $y, $color[$value['color']], $fontname,$newtext);
			$newtesto = wordwrap($testo, 40, "'n", true);
			imagettftext($im, $value['font-size'], 0, $xe, $ye, $color[$value['color']], $fontname,$newtesto);
			// add 32px to the line height for the next text block
		}
			// create the image
			imagejpeg($im, $file, $quality);
	//}
		return $file;
}
function center_text($string, $font_size){
			global $fontname;
			$image_width = 800;
			$dimensions = imagettfbbox($font_size, 0, $fontname, $string);
			return ceil(($image_width - $dimensions[4]) / 2);
}
	$user = array(
		array(
			'name'=> '',
			'font-size'=>'9',
			'gatto'=>$_POST['gatto'],
			'color'=>'grey'),
		array(
			'name'=> '',
			'font-size'=>'16',
			'color'=>'grey'),
		array(
			'name'=> '',
			'font-size'=>'13',
			'color'=>'green'
			)
	);

	$user = array(
		array(
			'name'=> $_POST['name'],
			'font-size'=>'9',
			'gatto'=>$_POST['gatto'],
			'color'=>'grey'),
		array(
			'name'=> $_POST['job'],
			'font-size'=>'16',
			'color'=>'grey'),
		array(
			'name'=> $_POST['email'],
			'font-size'=>'13',
			'color'=>'green'
			)
	);

// 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">
	<div class="col-xs-12" id="asd">
	  <img src="<?=$filename;?>" width="1000" height="500"/><br/><br/>
	</div>
</div>
<ul>
<?php if(isset($error)){
	foreach($error as $errors){
		echo '<li>'.$errors.'</li>';
	}
}?>
</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>	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>

您是否检查过封面目录的权限?将其设置为 644 或 777。

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

他打败了我,但是:

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

我忘了:如果您(您的网络服务器(对该目录没有写入权限。你不能直接chmod那个目录,你需要从shell中获取Chown或chmod的所有权。

在 Linux 终端中

sudo chmod 777 /some/directory