Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Delete file when done - how?

  • 26-05-2008 9:39am
    #1
    Registered Users, Registered Users 2 Posts: 1,262 ✭✭✭


    Hi folks,

    I'm working on a project which involves the creation of images using the php gd image library.

    The image is created on the fly... it's basically a graph based on user input. Once it has been displayed, it won't be used again.

    Each image is given a random filename so there are no conflicts when many users are viewing the same page.

    But... what do I do with the file afterwards? Is it ok to delete the file in PHP once it has been rendered?

    The PHP would look like

    [Image Creation Code]

    echo [image]

    [delete image code]

    Are there issues here? In effect, the image would be rendered on the users browser but the file wouldn't exist any more.

    What are my other options? I could run a cron job and delete all files every so -often but that seems cumbersome.

    Suggestions?


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Is there any reason why you *have* to save it temporarily. The GD library allows you to output the image binary directly to the browser without saving/caching it.

    You basically do something like

    <img src="./myImageScript.php?param1=x&param2=y" />


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    Agreeing with seamus, if you don't need to store the image, don't write it out to file.


  • Registered Users, Registered Users 2 Posts: 1,262 ✭✭✭di11on


    Thanks guys... working on this.

    For some reason, the code works ok when writing image to a file and then displaying... but I can't get it to work when outputting directly to browser... maybe the code is generating warnings or something and corrupting the output stream?


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    di11on wrote: »
    Thanks guys... working on this.

    For some reason, the code works ok when writing image to a file and then displaying... but I can't get it to work when outputting directly to browser... maybe the code is generating warnings or something and corrupting the output stream?
    Are you trying to output the image inline with other content?

    The script needs to generate a pure image to render correctly in a browser; so you would, for example, have one file "image.php" generating the image (and nothing else) and then a regular HTML image tag calling the script as though it were an image, as per seamus' reply above.


Advertisement