hey guys
I hope you doing well :P
am working on simple graphic script which gather some information and write it on image then show it to the user
on localhost the project run perfectly as it supposed to do.
when I uploaded to live server ( free hosting servers ) its seems it cannot create image on server, I've tried many methods for saving images but no luck, here is is my peace of code

$my_img = imagecreatefrompng ("background.PNG");
$my_avt = imagecreatefrompng($avatar);
imagestring( $my_img, 5, 70, 35, "Username", $text_black );
//doing some stuff to get width, height
imagecopy($my_img, $my_avt, imagesx($my_img) - $sx - $marge_right, imagesy($my_img) - $sy - $marge_bottom, 0, 0, imagesx($my_avt), imagesy($my_avt));
$filename = "username";
$directory = $filename.".png";
chmod($directory,0755);
imagepng($my_img, $directory, 0, NULL);
imagedestroy($my_img);
if (file_exists($directory)){
echo '<img src="'.$directory.'" />';
}else{
echo 'Cannot create picture on this server';
}

but nothing saved on server.

Dani AI

Generated

Good catch on the case-sensitivity, . On Linux, both the source filenames and the file you later reference in the HTML must match exactly. A common gotcha is saving as Username.PNG but rendering with username.png; the file exists, but the browser 404s because the cases differ.

If anyone still cannot save after fixing case, check three things:

  • Use a filesystem path when writing, not a URL. Relative paths may point somewhere unexpected on shared hosting. Prefer an absolute path based on __DIR__.
  • Ensure the destination directory (not the file) is writable by PHP. Set directory perms up front; do not chmod a file before it exists. Typical perms: directories 0755 (or 0775 on group-writable setups), files 0644.
  • Fail loudly. Check that GD is loaded and that imagepng() returns true, then inspect error_get_last().

Example pattern you can drop in to narrow issues:

error_reporting(E_ALL); ini_set('display_errors', 1);

if (!extension_loaded('gd') || !function_exists('imagepng')) {
    die('GD not available on this host.');
}

$webPath = 'images/out/username.png';                   // what the browser will load
$fsPath  = __DIR__ . '/images/out/username.png';        // where PHP writes

$dir = dirname($fsPath);
if (!is_dir($dir)) { mkdir($dir, 0755, true); }
if (!is_writable($dir)) { die('Directory not writable: ' . $dir); }

// $im should be your GD image resource at this point
$ok = imagepng($im, $fsPath);
if (!$ok) { var_dump(error_get_last()); exit; }

chmod($fsPath, 0644);                                   // optional
echo '<img src="' . $webPath . '" alt="">';

On some free hosts, open_basedir or read-only storage can also block writes. If the checks above pass but saving still fails, look for open_basedir in phpinfo or the error log.

am sorry for this disturbing but I solve my problem
its was silly of me not noticing the extension for file, its was written as PNG not png so linux server is case sensitive for these thing :P
have a nice day .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.