PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 10, 2022

[FIXED] how to store information in dump through php

 October 10, 2022     gd, html, php     No comments   

Issue

I want to store images created by php in real time. Currently each image is destroyed after creation, but instead I want to store the images in an unique folder on my website.

I have seen many websites that use a dedicated dump folder, e.g. http://www.example.com/dump/4592898349.jpg, and I was wondering if someone could explain to me how I could do that.

This is my html code with the form that starts the image generation:

<html>
    <body>
        <form action="result.php" method="get">
            <input type="text" name="name" id="name">
            <input type="button" name="submit" id="submit">
        </form>
    </body>
</html>

And here is my php code, which creates the image with the given text:

<?php
    header('Content-type: image/jpeg');
    $jpg_image = imagecreatefromjpeg('Desert.jpg');
    $white = imagecolorallocate($jpg_image, 73, 41, 236);
    $font_path = 'OpenSans-Italic.TTF';
    $text = $_GET['name'] ;
    imagettftext($jpg_image, 25, 0, 75, 50, $white, $font_path, $text);
    imagejpeg($jpg_image);
    imagedestroy($jpg_image); 
?>

However, I still don't know where would be the best place to save the image.


Solution

change

imagejpeg($jpg_image);

to

imagejpeg($jpg_image,"imagefolderpath/image.jpg");

that will write the image to file, and not output the image...so...

$image_url="dump/".rawurlencode(trim($text)).".jpg";
imagejpeg($jpg_image,$image_url);
readfile($image_url);


Answered By - RightClick
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing