0

I have modified a project to insert a text into an image. It works perfectly on local server but on remote he says: The requested URL /covers/03c7c0ace395d80182db07ae2c30f034.jpg was not found on this server.

The script doesn't create the image but on my local server it works. GD and Freefont are installed so i don't know what to do Please help me

<?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>
Matteo Pennisi
  • 404
  • 3
  • 7
  • have you looked into pathing as this can be diffrent on actual servers as they like to use the full path, rather that relative, not http:/// but somthign like: /home/mysite.com/html/imgs etc โ€“ Simon Davies Feb 07 '16 at 20:10
  • ./ ? in the server there is a www forder and a html folder inside of it. what tipe of path i have to use? โ€“ Matteo Pennisi Feb 07 '16 at 20:27
  • you will get this form you server control panel etc, could run a phpinfo page to find it, have alook at this http://stackoverflow.com/questions/6079479/how-to-get-the-absolute-path-to-the-public-html-folder โ€“ Simon Davies Feb 07 '16 at 20:37

2 Answers2

0

Have you checked the permission for the covers directory? Set it to 644 or 777.

I am assuming you are running the project locally on Windows. Windows handles permissions differently than Linux. That's why it works locally but not on your remote server.

farooq
  • 479
  • 4
  • 14
0

He beat me to it, but :

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

I forgot: If you (your webserver) don't have write access on that directory. You can't chmod that directory directly , you need to take ownership with Chown or chmod from a shell.

in Linux terminal

sudo chmod 777 /some/directory