A couple GD image questions

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default A couple GD image questions

    I have been working on the below snippet of code I found some place
    and have a couple questions on it since I am not real femiliar with
    the GD image commands.

    1. How would I define a custom path to save the pictures in instead of
    just putting the finished pictures in the same directory as the php
    file.

    2. How could I use the original file name of the picture and store
    that in the database rather than renaming the file.

    This is what I am working with
    --------

    <?php include 'db_connect.php'; ?>
    <html>
    <head>
    <title>Upload a picture to your article</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    </head>
    <body>
    <?php
    articleid = artid;

    //begin photo upload code
    if (isset(_POST['photosubmit']))
    {
    // Filename to store image as (no extention)
    FILENAME= rand(0,999999999);
    // Width to reszie image to (in pixels)
    RESIZEWIDTH=300;
    // Width to reszie image to (in pixels)
    RESIZEHEIGHT=400;
    //start image function
    function
    ResizeImage(im,maxwidth,maxheight,name){
    width = imagesx(im);
    height = imagesy(im);
    if((maxwidth && width >
    maxwidth) || (maxheight && height
    > maxheight)){
    if(maxwidth && width >
    maxwidth){
    widthratio = maxwidth/width;
    RESIZEWIDTH=true;
    }
    if(maxheight && height >
    maxheight){
    heightratio = maxheight/height;
    RESIZEHEIGHT=true;
    }
    if(RESIZEWIDTH && RESIZEHEIGHT){
    if(widthratio < heightratio){
    ratio = widthratio;
    }else{
    ratio = heightratio;
    }
    }elseif(RESIZEWIDTH){
    ratio = widthratio;
    }elseif(RESIZEHEIGHT){
    ratio = heightratio;
    }
    newwidth = width * ratio;
    newheight = height *
    ratio;
    if(function_exists("imagecopyresampled")){
    newim =
    imagecreatetruecolor(newwidth, newheight);
    imagecopyresampled(newim,
    im, 0, 0, 0, 0, newwidth, newheight, width,
    height);
    }else{
    newim = imagecreate(newwidth,
    newheight);
    imagecopyresized(newim,
    im, 0, 0, 0, 0, newwidth, newheight, width,
    height);
    }
    ImageJpeg (newim,name .
    ".jpg");
    ImageDestroy (newim);
    } else {
    ImageJpeg (im,name . ".jpg");
    }
    }

    //end image function
    if(_FILES['image']['size']){
    if(_FILES['image']['type']
    == "image/pjpeg" ||
    _FILES['image']['type'] ==
    "image/jpeg"){
    im =
    imagecreatefromjpeg(_FILES['image']['tmp_name']);
    }elseif(_FILES['image']['type']
    == "image/x-png" ||
    _FILES['image']['type'] ==
    "image/png"){
    im =
    imagecreatefrompng(_FILES['image']['tmp_name']);
    }elseif(_FILES['image']['type']
    == "image/gif"){
    im =
    imagecreatefromgif(_FILES['image']['tmp_name']);
    }
    if(im){
    if(file_exists("FILENAME.jpg")){
    unlink("FILENAME.jpg");
    }

    ResizeImage(im,RESIZEWIDTH,RESIZEHEIGHT,FILENA ME);
    ImageDestroy (im);
    }
    //Submit picture


    insert = "INSERT INTO pictures (
    article_ref,
    pic_name)
    VALUES (
    'articleid',
    '".FILENAME.".jpg')";

    article_pic = db_object->query(insert);

    if (DB::isError(article_pic)) {
    die(article_pic->getMessage());
    }

    db_object->disconnect();

    ?>
    <B>Picture added successfully!</B> You can either
    close this window or upload more pictures.

    <?php

    }
    }
    //end upload photo
    ?>

    <form enctype="multipart/form-data"
    method="post">
    <b>Upload Image</b><br>
    <input type="file" name="image"
    size="50"><br>
    <input type="submit" name="photosubmit"
    value="Upload Photo"
    onclick='refreshIframe()'>
    </form>

    </body>
    </html>

    --------

    Thanks a million for any help on this problem!!! :D



    ----------------------------------------
    The post originated from PHP Freaks:
    ----------------------------------------
    [url]http://www.phpfreaks.com[/url]
    [url]http://www.phpfreaks.com/forums[/url]


    Vertex Guest

  2. Similar Questions and Discussions

    1. A couple of questions
      I have a Canon A60 and .... 1) I really need to pick up some rechargable AA NiMH batteries. I see packages like this...
    2. Flash and .NET...a couple questions
      I was thinking about creating an app using flash and .net but had a few questions on the best way to go about doing things. Is it best practise to...
    3. A couple of questions before I buy....
      Hi, I have been playing with a 30 day trial version of Contribute 3 and have a couple of questions before I buy. 1. My page uses CSS buttons,...
    4. Please help with a couple questions!!!
      I just bought adobe 6.0 standard and my system is win. xp I wrote my book in ms word and then hit the adobe convert button and when it converted...
    5. I have a couple of questions.
      First, I would like to know if there is anyway to add a watermark to pictures, that will only show up only when the photo is printed. My husband...
  3. #2

    Default Re: A couple GD image questions

    Try using this:

    move_uploaded_file ( string filename, string destination)





    ----------------------------------------
    The post originated from PHP Freaks:
    ----------------------------------------
    [url]http://www.phpfreaks.com[/url]
    [url]http://www.phpfreaks.com/forums[/url]


    parksmike Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139