【问题标题】:PHP | Create image works on local server but not remote hostPHP |创建图像适用于本地服务器但不适用于远程主机
【发布时间】:2016-02-07 19:44:19
【问题描述】:

我修改了一个项目以将文本插入图像。它在本地服务器上完美运行,但在远程他说: 在此服务器上找不到请求的 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>

【问题讨论】:

  • 您是否研究过路径,因为这在实际服务器上可能有所不同,因为他们喜欢使用完整路径,而不是相对路径,而不是 http:/// 而是类似:/home/mysite.com /html/imgs 等
  • ./ ?在服务器中有一个 www forder 和一个 html 文件夹。我必须使用什么路径?
  • 你会得到这个表单你的服务器控制面板等,可以运行一个 phpinfo 页面来找到它,看看这个stackoverflow.com/questions/6079479/…

标签: php server gd


【解决方案1】:

你检查过covers目录的权限吗?将其设置为 644 或 777。

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

【讨论】:

    【解决方案2】:

    他打败了我,但是:

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

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

    在 Linux 终端中

    sudo chmod 777 /some/directory
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-03
      • 2012-09-23
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      相关资源
      最近更新 更多