stupid picture uploading using PHP

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default stupid picture uploading using PHP

    I have been trying to upload a file to a folder on the server, and display the
    filename in the database, so that i can link to this file and display it. The
    code i have works in one example, but not in the one that i am currently
    working with and i have no idea why. I have ammended it correctly, but it still
    doesnt work, can any body help? p.s. i think its the upload bit is at the end,
    but am not entirely sure.
    any help would be great.

    Here is my code:
    <?php require_once('Connections/mysql.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
    $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
    "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
    }

    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] ==
    "form1")) {
    $insertSQL = sprintf("INSERT INTO artistmembers (email, membernameid,
    membername, memberpicture, membertext, memberposition) VALUES (%s, %s, %s, %s,
    %s, %s)",
    GetSQLValueString($HTTP_POST_VARS['email'], "text"),
    GetSQLValueString($HTTP_POST_VARS['membernameid'],
    "int"),
    GetSQLValueString($HTTP_POST_VARS['membername'],
    "text"),
    GetSQLValueString($_FILES['memberpicture']['name'], "text"),
    GetSQLValueString($HTTP_POST_VARS['membertext'],
    "text"),
    GetSQLValueString($HTTP_POST_VARS['memberposition'],
    "text"));

    mysql_select_db($database_mysql, $mysql);
    $Result1 = mysql_query($insertSQL, $mysql) or die(mysql_error());
    }

    mysql_select_db($database_mysql, $mysql);
    $query_loadmember = "SELECT * FROM artistmembers";
    $loadmember = mysql_query($query_loadmember, $mysql) or die(mysql_error());
    $row_loadmember = mysql_fetch_assoc($loadmember);
    $totalRows_loadmember = mysql_num_rows($loadmember);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <!-- DW6 -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <!-- TemplateBeginEditable name="doctitle" -->
    <title>Untitled Document</title>
    <!-- TemplateEndEditable --><link rel="stylesheet" href="3col_leftNav.css"
    type="text/css">
    <style type="text/css">
    <!--
    .style1 {color: #FFFFFF}
    .style8 {font-size: 10px}
    .style9 {font-size: 12px}
    -->
    </style>
    <!-- TemplateParam name="Headline1" type="boolean" value="true" -->
    <!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
    </head>
    <body>
    <div id="masthead">
    <h1 id="siteName">Soundstage</h1>
    <div id="globalNav">
    <a href="register.html">register</a> | <a href="login.html">login</a> | <a
    href="logout.html">logout</a> | <a href="#">basket</a> |
    <a href="#">checkout</a> |
    </div>
    <h2 class="style1" id="pageName">reviews...</h2>
    <div id="breadCrumb">
    <a href="#">breadcrumb</a> / <a href="#">breadcrumb</a> / <a
    href="#">breadcrumb</a> /
    </div>
    </div>
    <div id="navBar">
    <div id="search">
    <form action="#">
    <label>search</label>
    <input name="searchFor" type="text" size="10">
    <input name="goButton" type="submit" value="go">
    </form>
    </div>
    <div id="sectionLinks">
    <h3>Section Links</h3>
    <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="artists.html">Artists</a></li>
    <li><a href="genre.html">Genre</a></li>
    <li><a href="city.html">City</a></li>
    <li><a href="reviews.html">Reviews</a></li>
    <li><a href="#">Section Link</a></li>
    </ul>
    </div>
    <div class="relatedLinks">
    <h3>Related Link Category</h3>
    <ul>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    </ul>
    </div>
    <div class="relatedLinks">
    <h3>Related Link Category</h3>
    <ul>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    <li><a href="#">Related Link</a></li>
    </ul>
    </div>
    </div>
    <!--end navBar div -->
    <div id="headlines">
    <h3>Artist of the week:</h3>
    <p>&nbsp;
    </p>
    <div id="advert">
    <img src="" alt="" width="107" height="66"> Ad copy ad copy ad copy. Ad
    copy ad copy.
    </div>
    </div>
    <!--end headlines -->
    <div id="content"> </div>


    <!--end content -->
    <table width="53%" height="34" border="0">
    <tr>
    <td><a href="bandsection1.php"></a>
    <p align="center"><a href="bandsection1.php">back to edit
    band</a></p></td>
    </tr>
    </table>
    <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
    <table align="center">
    <tr valign="baseline">
    <td nowrap align="right">Membername:</td>
    <td><input type="text" name="membername" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right">Memberpicture:</td>
    <td><input type="file" name="memberpicture" value="uploadfile"
    size="32"></td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right" valign="top">Membertext:</td>
    <td> <textarea name="membertext" cols="50" rows="5"></textarea> </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right">Memberposition:</td>
    <td><input type="text" name="memberposition" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right">&nbsp;</td>
    <td><input name="submit" type="submit" value="Insert Record"></td>
    </tr>
    </table>
    <input type="hidden" name="email" value="">
    <input type="hidden" name="membernameid" value="">
    <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p>&nbsp;</p>
    <div align="left">
    <p>&nbsp;</p>
    </div>
    <div id="siteInfo">
    <img src="" width="44" height="22"> <a href="#">About Us</a> | <a
    href="#">Site
    Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> |
    &copy;2003
    Company Name
    </div>
    <br>
    <p>&nbsp;</p>

    </body>
    </html>
    <?
    echo $HTTP_POST_VARS['memberpicture'];
    $uploaddir = '//ftpserver/www/bla/bla/bla/bla/';
    $uploadfile = $uploaddir . basename($_FILES['memberpicture']['name']);
    echo $uploadfile;

    echo '<pre>';
    if (move_uploaded_file($_FILES['memberpicture']['tmp_name'], $uploadfile)) {
    echo "Your a mastermind.....\n";
    }
    else {
    echo "Possible file upload attack!\n";
    }

    echo 'Here is some more debugging info:';
    print_r($_FILES);
    print "</pre>";

    ?>
    <?php
    mysql_free_result($loadmember);
    ?>

    bethan81 Guest

  2. Similar Questions and Discussions

    1. Help! Did something stupid with CF Administrator
      I've been trying to use a FileMaker Pro database as a datasource using a local CF test server (I'm on Mac OS X so I don't have Access but have FM...
    2. Stupid Mistake
      I am using CFMX 6.1 and I was playing with the settings in Sandbox Security and now I cannot get access to CF Admin. I get the following error: ...
    3. Im really stupid so please help me
      how do i make a loading animation for my site and make it appear when i a page is loading?
    4. Stupid C# question Please help!
      I'm used to writing my code in VBscript but I have to do this project in C#. I've written some functions on my ASP.Net page and I'm getting an...
    5. Stupid dreamweaver
      Does anyone have the same problem with rollovers as I have? When you put buttons on a page and attach the behaviors, the rollovers stay open, or they...
  3. #2

    Default Re: stupid picture uploading using PHP



    On Thu, 3 Mar 2005 01:25:27 +0000 (UTC), bethan81
    <webforumsuser@macromedia.com> wrote:
    > I have been trying to upload a file to a folder on the server, and
    > display the
    > filename in the database, so that i can link to this file and display
    > it. The
    > code i have works in one example, but not in the one that i am currently
    > working with and i have no idea why. I have ammended it correctly, but
    > it still
    > doesnt work, can any body help? p.s. i think its the upload bit is at
    > the end,
    > but am not entirely sure.
    > any help would be great.
    >
    > Here is my code:
    > <?php require_once('Connections/mysql.php'); ?>
    > <?php
    > function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
    > $theNotDefinedValue = "")
    > {
    > $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) :
    > $theValue;
    >
    > switch ($theType) {
    > case "text":
    > $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    > break;
    > case "long":
    > case "int":
    > $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    > break;
    > case "double":
    > $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
    > "NULL";
    > break;
    > case "date":
    > $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    > break;
    > case "defined":
    > $theValue = ($theValue != "") ? $theDefinedValue :
    > $theNotDefinedValue;
    > break;
    > }
    > return $theValue;
    > }
    >
    > $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
    > if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    > $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
    > }
    >
    > if ((isset($HTTP_POST_VARS["MM_insert"])) &&
    > ($HTTP_POST_VARS["MM_insert"] ==
    > "form1")) {
    > $insertSQL = sprintf("INSERT INTO artistmembers (email, membernameid,
    > membername, memberpicture, membertext, memberposition) VALUES (%s, %s,
    > %s, %s,
    > %s, %s)",
    > GetSQLValueString($HTTP_POST_VARS['email'],
    > "text"),
    > GetSQLValueString($HTTP_POST_VARS['membernameid'],
    > "int"),
    > GetSQLValueString($HTTP_POST_VARS['membername'],
    > "text"),
    > GetSQLValueString($_FILES['memberpicture']['name'], "text"),
    > GetSQLValueString($HTTP_POST_VARS['membertext'],
    > "text"),
    > GetSQLValueString($HTTP_POST_VARS['memberposition'],
    > "text"));
    >
    > mysql_select_db($database_mysql, $mysql);
    > $Result1 = mysql_query($insertSQL, $mysql) or die(mysql_error());
    > }
    >
    > mysql_select_db($database_mysql, $mysql);
    > $query_loadmember = "SELECT * FROM artistmembers";
    > $loadmember = mysql_query($query_loadmember, $mysql) or
    > die(mysql_error());
    > $row_loadmember = mysql_fetch_assoc($loadmember);
    > $totalRows_loadmember = mysql_num_rows($loadmember);
    > ?>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    > "http://www.w3.org/TR/html4/loose.dtd">
    > <html>
    > <!-- DW6 -->
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > <!-- TemplateBeginEditable name="doctitle" -->
    > <title>Untitled Document</title>
    > <!-- TemplateEndEditable --><link rel="stylesheet"
    > href="3col_leftNav.css"
    > type="text/css">
    > <style type="text/css">
    > <!--
    > .style1 {color: #FFFFFF}
    > .style8 {font-size: 10px}
    > .style9 {font-size: 12px}
    > -->
    > </style>
    > <!-- TemplateParam name="Headline1" type="boolean" value="true" -->
    > <!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
    > </head>
    > <body>
    > <div id="masthead">
    > <h1 id="siteName">Soundstage</h1>
    > <div id="globalNav">
    > <a href="register.html">register</a> | <a
    > href="login.html">login</a> | <a
    > href="logout.html">logout</a> | <a href="#">basket</a> |
    > <a href="#">checkout</a> |
    > </div>
    > <h2 class="style1" id="pageName">reviews...</h2>
    > <div id="breadCrumb">
    > <a href="#">breadcrumb</a> / <a href="#">breadcrumb</a> / <a
    > href="#">breadcrumb</a> /
    > </div>
    > </div>
    > <div id="navBar">
    > <div id="search">
    > <form action="#">
    > <label>search</label>
    > <input name="searchFor" type="text" size="10">
    > <input name="goButton" type="submit" value="go">
    > </form>
    > </div>
    > <div id="sectionLinks">
    > <h3>Section Links</h3>
    > <ul>
    > <li><a href="index.html">Home</a></li>
    > <li><a href="artists.html">Artists</a></li>
    > <li><a href="genre.html">Genre</a></li>
    > <li><a href="city.html">City</a></li>
    > <li><a href="reviews.html">Reviews</a></li>
    > <li><a href="#">Section Link</a></li>
    > </ul>
    > </div>
    > <div class="relatedLinks">
    > <h3>Related Link Category</h3>
    > <ul>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > </ul>
    > </div>
    > <div class="relatedLinks">
    > <h3>Related Link Category</h3>
    > <ul>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > <li><a href="#">Related Link</a></li>
    > </ul>
    > </div>
    > </div>
    > <!--end navBar div -->
    > <div id="headlines">
    > <h3>Artist of the week:</h3>
    > <p>&nbsp;
    > </p>
    > <div id="advert">
    > <img src="" alt="" width="107" height="66"> Ad copy ad copy ad
    > copy. Ad
    > copy ad copy.
    > </div>
    > </div>
    > <!--end headlines -->
    > <div id="content"> </div>
    > <!--end content -->
    > <table width="53%" height="34" border="0">
    > <tr>
    > <td><a href="bandsection1.php"></a>
    > <p align="center"><a href="bandsection1.php">back to edit
    > band</a></p></td>
    > </tr>
    > </table>
    > <form method="post" name="form1" action="<?php echo $editFormAction;
    > ?>">
    > <table align="center">
    > <tr valign="baseline">
    > <td nowrap align="right">Membername:</td>
    > <td><input type="text" name="membername" value="" size="32"></td>
    > </tr>
    > <tr valign="baseline">
    > <td nowrap align="right">Memberpicture:</td>
    > <td><input type="file" name="memberpicture" value="uploadfile"
    > size="32"></td>
    > </tr>
    > <tr valign="baseline">
    > <td nowrap align="right" valign="top">Membertext:</td>
    > <td> <textarea name="membertext" cols="50" rows="5"></textarea>
    > </td>
    > </tr>
    > <tr valign="baseline">
    > <td nowrap align="right">Memberposition:</td>
    > <td><input type="text" name="memberposition" value=""
    > size="32"></td>
    > </tr>
    > <tr valign="baseline">
    > <td nowrap align="right">&nbsp;</td>
    > <td><input name="submit" type="submit" value="Insert Record"></td>
    > </tr>
    > </table>
    > <input type="hidden" name="email" value="">
    > <input type="hidden" name="membernameid" value="">
    > <input type="hidden" name="MM_insert" value="form1">
    > </form>
    > <p>&nbsp;</p>
    > <div align="left">
    > <p>&nbsp;</p>
    > </div>
    > <div id="siteInfo">
    > <img src="" width="44" height="22"> <a href="#">About Us</a> | <a
    > href="#">Site
    > Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a>
    > |
    > &copy;2003
    > Company Name
    > </div>
    > <br>
    > <p>&nbsp;</p>
    > </body>
    > </html>
    > <?
    > echo $HTTP_POST_VARS['memberpicture'];
    > $uploaddir = '//ftpserver/www/bla/bla/bla/bla/';
    > $uploadfile = $uploaddir . basename($_FILES['memberpicture']['name']);
    > echo $uploadfile;
    >
    > echo '<pre>';
    > if (move_uploaded_file($_FILES['memberpicture']['tmp_name'],
    > $uploadfile)) {
    > echo "Your a mastermind.....\n";
    > }
    > else {
    > echo "Possible file upload attack!\n";
    > }
    >
    > echo 'Here is some more debugging info:';
    > print_r($_FILES);
    > print "</pre>";
    >
    > ?>
    > <?php
    > mysql_free_result($loadmember);
    > ?>
    >
    We currently have an extension that does this work for you. We have had
    great result generating upload engine on secure way specially when
    dealing with PHP

    You might want to check our extension here:
    [url]http://www.interaktonline.com/Products/Dreamweaver-Extensions/ImpAKT/Overview/[/url]

    --
    Alexandro Colorado
    ------------------------------
    Support Engineer
    InterAKT Online
    [url]http://www.interaktonline.com[/url]
    Tel: 40(21) 312.5312
    Alexandro Colorado Guest

  4. #3

    Default Re: stupid picture uploading using PHP

    hi, that would be useful if i could install it, i am currently using the university macromedia mx software, and it would be impossible to upgrade the extension. Thanks anyway.
    bethan81 Guest

  5. #4

    Default Re: stupid picture uploading using PHP

    You miss the enctype='multipart/form-data' inside the form tag.

    Felix
    [email]webmaster@felixone.it[/email]
    [url]http://www.felixone.it[/url]
    Felix1 Guest

  6. #5

    Default Re: stupid picture uploading using PHP

    hi thanks so much for your help, sorry about the messy code!!!!!!!
    bethan81 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