Thread: PHP/Databse

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    19
    Rep Power
    0
    I am setting up a virtual squadron database. I want useres to be able to add their logo to there entry. So Imade it so that they type te URL and it use the <.image src="uRL here".> command in HTML

    Is there any way to limit the size of the image or do I have to have them upload it...and if so how do I do that?

    Or is tere any way to detect the image size...then resize it smaller maintaininng the smae aspect ratio?
    Thanks,
    Ryan

    [This message has been edited by Ryan (edited April 01, 2000).]
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    6
    Rep Power
    0
    Are you having the users upload the file with a form? if so, you can use the following form, and you can set the max size the users may upload:

    <form enctype="multipart/form-data" action="" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="15000">
    <input name="uploaded" type="file">
    <input type="submit" value="Upload">
    </form>

    You may use the getimagesize() function to get information about the image uploaded. It puts information into an array, and you can access different things. For example, say you did something liek this:
    $image_size = getimagesize($image_file)

    then ur width would be $image_size[0] and your height would be $image_size[1]. There is also other informatino stored in this array. You can find all the documentation on php.net. To change hte size, and maintain the aspect ratio, you could do something like this:

    if ($image_size[0] > 350) {
    $width = 350;
    $height = (350 * $image_size[1])/$image_size[0];
    } else {
    $width = $image_size[0];
    $height = $image_size[1];
    }

    This will resize any image that's wider than 350 px. Then you would do something liek this:

    echo "<img src='image.gif' width=$width height=$height alt='' border='1'>

    Hope this helps
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    19
    Rep Power
    0
    thanks ill try it!

    Ryan
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    19
    Rep Power
    0
    I cant get it to work

    Here is my Code:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <TITLE>The 54th Screamin Devils - Squadrons Database</TITLE>
    <META name="description" content=""><META name="keywords" content="">
    <META name="generator" content="CuteHTML">

    <style>
    A:Link {background:#003344; color:#F5F5DC;text-decoration:none;}

    A:Visited {background:#003344; color:#F5F5DC;text-decoration:none;}

    A:Hover {background:#990000; color:#F5F5DC; text-decoration:none;}
    </style>
    </HEAD>

    <BODY BGCOLOR="#8ba68b" TEXT="#000000">

    <TABLE BORDER=0 CELLSPACING=0 width="100%" cellpadding="0">
    <TR>
    <TD COLSPAN=2 background="http://www.cfsquad.com/menu-blanks.gif"><DIV ALIGN="right"><img src="http://www.cfsquad.com/header.gif"></div></TD>
    </TR>

    <tr>
    <TD bgcolor="#003344" width="15%" valign="top">


    <!-- Menu --> <? virtual("/manu.shtml"); ?>


    <br>

    <font face="Arial" size="1" color="beige"><!-- counter --> <!--#exec cgi="/cgi-bin/counter.pl"--></font>

    </td>

    <TD valign="top" bgcolor="8ba68b">

    <!-- Main Section -->

    <div align="left"><img src="http://www.cfsquad.com/cor1.gif"></div>
    <div align="center" ><FONT FACE="Arial" SIZE=1 COLOR="#000000">


    <?

    //
    // Connect to local mySQL database
    //
    $db = mysql_connect("localhost", "online", "*****");

    //
    // Select your database
    //
    mysql_select_db("online", $db);

    //
    // Message to display when adding is complete
    //
    $msgdone = "<font face="Arial" size="2" color="Black">Success! Your Squadron has been added to the Database</font> <br>Your Listing is below.<br> Click <a href="http://www.cfsquad.com/php/view.php3?view=all">here</a> to view the rest of the Database";

    //
    // using a query from te form helps out somewhat
    //
    if ($add == "yes")
    {
    //
    // this inserts a new "profile" into the fields selected. I automatically increments the ID number
    //
    mysql_query("INSERT INTO squad_db (ID, SQUADNAME, CONTACT, URL, SHIST, CO, PASS) VALUES (0, '$squadname', '$contact', '$url', '$shist', '$co', '$pass')");

    //
    // Prints message if all goes well
    //
    print("$msgdonen");
    }

    //
    // Select a squadron from the server with the query $id=$id
    //

    $image_size = getimagesize($logo);

    $imageName = basename($logo);


    if ($image_size[0] > 100)
    {
    $width = 100;
    $height = (100 * $image_size[1])/$image_size[0];
    }
    else
    {
    $width = $image_size[0];
    $height = $image_size[1];
    }

    if($copy)
    {
    copy($logo, "/home/online/www/images/" . $ImageName);
    }
    elseif(!($copy))
    {
    print("No file of function specified for copy!n");
    }

    ?>


    <?
    print "<table border="1" cellpadding="0" align="center" width="60%">n";
    print "<tr><td rowspan="6">";
    print "<img src="$logo"></td>";
    print "<td><font face="Arial" size="2">Squadron Name:</font></td><td align="right"><font face="Arial" size="2">$squadname</font></td>n";
    print "</tr><tr>n";
    print "<td><font face="Arial" size="2">Squadron Contact:</font></td><td align="right"><font face="Arial" size="2"><a href="mailto:$contact">$co</a></font></td>n";
    print "</tr><tr>n";
    print "<td><font face="Arial" size="2">Squadron URL:</font></td><td align="right"><font face="Arial" size="2"><a href="$url">$url</a></font></td>n";
    print "</tr><tr>n";
    print "<td><font face="Arial" size="2">Short History:</font></td><td align="right"><font face="Arial" size="2">$shist</font></td>n";
    print "</tr><tr>n";
    print "<td><font face="Arial" size="2">C/O:</font></td><td align="right"><font face="Arial" size="2">$co</font></td>n";
    print "</tr><tr>n";
    print "<td><font face="Arial" size="2">Password:</font></td><td align="right"><font face="Arial" size="2">$pass</font></td>n";
    print "</tr>";

    print "</table>n";

    mail("$contact","Squadron Added",
    "Hello $co

    The Following information has been Submitted to the Squadrons Database at Cfsquad.com

    Squadron Name:$squadname
    Squadron Contact: $contact
    Squadron URL: $URL
    Short History: $SHIST
    Commanding Officer: $CO
    Logo: $logo
    Password: $Pass This is not in use yet. When the editing feature is added you will need this to do so.)

    Thankyou,
    CFSquad.com
    webmaster@cfsquad.com", "From: webmaster@cfsquad.com");
    ?>
    <br>

    </td></tr>
    <tr><td valign="bottom"><img src="http://www.cfsquad.com/bottom.gif" width="150"></td>
    <td></td>
    </tr>
    </table>
    </div>

    </BODY>
    </HTML>
    [/code]

    and to add the sqad:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <HTML>
    <HEAD>
    <TITLE>The 54th Screamin Devils - Squadrons Database</TITLE>


    <style>
    A:Link {background:#003344; color:#F5F5DC;text-decoration:none;}

    A:Visited {background:#003344; color:#F5F5DC;text-decoration:none;}

    A:Hover {background:#990000; color:#F5F5DC; text-decoration:none;}
    </style>
    </HEAD>

    <BODY BGCOLOR="#8ba68b" TEXT="#000000">

    <TABLE BORDER=0 CELLSPACING=0 width="100%" cellpadding="0">
    <TR>
    <TD COLSPAN=2 background="http://www.cfsquad.com/menu-blanks.gif"><DIV ALIGN="right"><img src="http://www.cfsquad.com/header.gif"></div></TD>
    </TR>

    <tr>
    <TD bgcolor="#003344" width="15%" valign="top">


    <!-- Menu --> <? virtual("/manu.shtml"); ?>


    <br>

    <font face="Arial" size="1" color="beige"><!-- counter --> <!--#exec cgi="/cgi-bin/counter.pl"--></font>

    </td>

    <TD valign="top" bgcolor="8ba68b">

    <!-- Main Section -->

    <div align="left"><img src="http://www.cfsquad.com/cor1.gif"></div>
    <div align="center" >

    <b><font face="Arial" size="3" color="#FFFFFF">Add Your Squad to the Database!</font>
    </b>
    <FONT FACE="Arial" SIZE=1 COLOR="#000000">

    <?
    //
    // This page has no PHP whatsoever except for this comment
    //
    ?>
    <form name="addsquad" action="addsquad.php3?add=yes " method="POST" enctype="multipart/form-data">
    <table border="0" cellpadding="2 cellspacing="0"><tr><td>

    <b><font face="Arial" size="2">Squad Name:</font></b> </td><td> <input type="text" name="squadname"><br>
    </tr><tr><td><b><font face="Arial" size="2">Contact Email:</font></b></td><td> <input type="text" name="contact"><br>
    </tr><tr><td><font face="Arial" size="2"><b>URL:</b></font></td><td> <input type="text" name="url"><br>
    </tr><tr><td><font face="Arial" size="2"><b>Short Hist:</b></font></td><td> <input type="text" name="shist"><br>
    </tr><tr><td><font face="Arial" size="2"><b>C/O:</b></font> </td><td> <input type="text" name="co"><br>
    </tr><tr><td><font face="Arial" size="2"><b>Logo: </b><font size="1">(No larger than 140X100)</font>:</font></td><td><input type="hidden" name="MAX_FILE_SIZE" value="15000">
    <input name="logo" type="file">
    </tr><tr><td><font face="Arial" size="2"><b>Password</b>:</font></td><td><input type="text" name="pass"><br></tr></table>
    <input type="submit" value="Add Squad">
    </form>

    <br>

    </td></tr>
    <tr><td valign="bottom"><img src="http://www.cfsquad.com/bottom.gif" width="150"></td>
    <td><font face="Arial" size="1">Copyright 199-2000 54th Screamin Devils</font></td>
    </tr>
    </table>
    </div>

    </BODY>
    </HTML>

    [/code]

    Any suggestions??

    Thanks,
    Ryan


    [This message has been edited by Ryan (edited April 02, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo