+ Reply to Thread
Results 1 to 8 of 8

Thread: PHP message upload.

  1. #1
    bigjoe4 is offline x10 Elder bigjoe4 is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    907

    PHP message upload.

    On this page: http://www.lights4yourpc.com/pictures.html I have an image upload thingy, but I want to add a field for the person to upload their name and a comment with their image aswell. The name/comment could be emailed to me or uploaded into some kind of text file or something.

    I want there to only be one 'submit' button for both the file upload and the name and comment.

    I don't have any idea how to do this as I just copy and pasted the code for the image upload thingy from somewhere else, so can anyone help me do this?

    I will give generous credits to whoever gets this working first.

    note: I know almost nothing about PHP
    Please visit my site: Circuit designer

  2. #2
    lszanto is offline x10Hosting Member lszanto is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    23

    Re: PHP message upload.

    That doesn't sound too hard, can you paste the image upload script here or PM it to me so that I can take a look at it and modify it?

  3. #3
    bigjoe4 is offline x10 Elder bigjoe4 is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    907

    Re: PHP message upload.

    Here it is.

    upload_file.php:

    Code:
    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 5000000))
      {
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
        if (file_exists("upload/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "folder/" . $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo "Invalid file";
      }
    ?>
    Last edited by bigjoe4; 04-26-2008 at 05:41 AM.
    Please visit my site: Circuit designer

  4. #4
    lszanto is offline x10Hosting Member lszanto is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    23

    Re: PHP message upload.

    Ok I have made it so it sends you an email after they have uploaded an image, if you need more information in the email or anything please just say and I'll fix it, you replace person@email.com with your email address.

    upload_file.php -
    PHP Code:
    <?php

    //Email function.
    function send_email($name$comment) {
        
    //Set vars.
        
    $to "person@email.com";
        
    $subject "Image uploaded by " $name;
        
    $message "An image has been uploaded, the details are below.\n\nName: " $name "\nComments: " $comments "\n\nThanks, your website";
        
    $from "From: <$name>";
        
        
    //Send email.
        
    mail($to$subject$message$from);
    }

    //Check for image types.
    if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 5000000) && isset($_POST['name']) && isset($_POST['comment'])) {
        
    //Check for an error.
        
    if ($_FILES["file"]["error"] > 0) {
            
    //If an error, tell the user.
            
    echo "Return Code: " $_FILES["file"]["error"] . "<br />";
        } else {
            
    //Show upload details.
            
    echo "Upload: " $_FILES["file"]["name"] . "<br />";
            echo 
    "Type: " $_FILES["file"]["type"] . "<br />";
            echo 
    "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo 
    "Temp file: " $_FILES["file"]["tmp_name"] . "<br />";
            
            
    //Check if the file exists.
            
    if (file_exists("upload/" $_FILES["file"]["name"])) {
                
    //If the file exists, tell the user.
                
    echo $_FILES["file"]["name"] . " already exists. ";
            } else {
                
    //Upload the image.
                
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" $_FILES["file"]["name"]);
                
    //Inform the user.
                
    echo "Stored in: " "folder/" $_FILES["file"]["name"];
                
                
    //Send the email.
                
    send_email($_POST['name'], $_POST['comment']);
            }
        }
        
    } else {
        
    //Tell the user file is invalid or they have left a field blank.
        
    echo "You have either left a field blank in the form or have uploaded the wrong kind of file, please go <a href=\"pictures.html\" >back</a> and try again.";
    }

    ?>
    And this is the html file for pictures.html -

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>High power lights for your computer</title>
    <link href="Favicon.ico" rel="SHORTCUT ICON">
    <META NAME="description" CONTENT="Flashing Lights for your PC."><META NAME="keywords" CONTENT=
    "Computer lights, PC lights, laser leds, flashing computer lights, computer leds, computer leds kit, multicolor computer LEDs, PC LEDs kit, Case LEDs, Case lights, Flashing 12 LEDs, 12V LEDs, Flashing 12V lights">
    <script type="text/javascript">
    <!--
    function SwapImage()
    {
       var doc=document, args=arguments;
       doc.$imgSwaps = new Array();
       for(var i=2; i<args.length; i+=2)
       {
          var elem=FindObject(args[i]);
          if(elem)
          {
             doc.$imgSwaps[doc.$imgSwaps.length]=elem;
             elem.$src=elem.src;
             elem.src=args[i+1];
          }
       }
    }
    // -->
    </script>
    <script type="text/javascript">
    <!--
    function FindObject(id, doc)
    {
       var child, elem;
       if(!doc)
          doc=document;
       if(doc.getElementById)
          elem=doc.getElementById(id);
       else
       if(doc.layers)
          child=doc.layers;
       else
       if(doc.all)
          elem=doc.all[id];
       if(elem)
          return elem;
       if(doc.id==id || doc.name==id)
          return doc;
       if(doc.childNodes)
          child=doc.childNodes;
       if(child)
       {
          for(var i=0; i<child.length; i++)
          {
             elem=FindObject(id,child[i]);
             if(elem)
                return elem;
          }
       }
       var frm=doc.forms;
       if(frm)
       {
          for(var i=0; i<frm.length; i++)
          {
             var elems=frm[i].elements;
             for(var j=0; j<elems.length; j++)
             {
                elem=FindObject(id,elems[i]);
                if(elem) return elem;
             }
          }
       }
       return null;
    }
    // -->
    </script>
    </head>
    <body background="purple-tile.gif" bgcolor="#330066" text="#000000" alink="#0000FF">
    <img src="Lights4yourPC.gif" id="Image1" alt="" align="top" border="0" width="704" height="150" style="position:absolute;left:0px;top:0px;width:704px;height:150px;z-index:0">
    <div id="bv_" style="position:absolute;left:0px;top:150px;width:118px;height:124px;z-index:1" align="center">
    <table border="0" cellpadding="0" cellspacing="0" id="NavigationBar1">
    
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="/"><img id="home" src="home.gif" alt="home" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'home','home-over.gif')" onmouseout="SwapImage(0,0,'home','home.gif')"></a></td>
    </tr>
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="pictures.html"><img id="pictures" src="pictures-over.gif" alt="pictures" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'pictures','pictures-over.gif')" onmouseout="SwapImage(0,0,'pictures','pictures-over.gif')"></a></td>
    </tr>
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="buy.html"><img id="buy" src="buy.gif" alt="buy" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'buy','buy-over.gif')" onmouseout="SwapImage(0,0,'buy','buy.gif')"></a></td>
    </tr>
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="links.html"><img id="links" src="links.gif" alt="links" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'links','links-over.gif')" onmouseout="SwapImage(0,0,'links','links.gif')"></a></td>
    </tr>
    </table>
    </div>
    <img src="line.gif" id="Image2" alt="" align="top" border="0" width="1" height="536" style="position:absolute;left:118px;top:150px;width:1px;height:1160px;z-index:2">
    <img src="fade.gif" id="Image3" alt="" align="top" border="0" width="118" height="348" style="position:absolute;left:0px;top:274px;width:118px;height:1036px;z-index:3">
    <div id="b_" style="position:absolute;left:124px;top:152px;width:574px;height:32px;z-index:4" align="left">
    
    <font style="font-size:27px" color="#FFFF99" face="Verdana"><b><u>Upload your images!</u></b></font></div>
    <div id="v_" style="position:absolute;left:124px;top:202px;width:560px;height:559px;z-index:5" align="left">
    
    <!-- PayPal Logo -->
    <a href="#" onclick="javascript:window.open('https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');"><img  src="space.gif" border="0" width="1" height="1" alt="Acceptance Mark" style="position:absolute;left:600px;top:0px"></a><!-- PayPal Logo -->
    
    <font style="font-size:16px" color="#FFFFFF" face="Verdana">Here you can upload pictures of your PC mods!<br>
    <br>
    Images will be checked by the administrator before being displayed.<br><br>
    Files must be in JPG format for upload.<br><br>
    
    <form action="upload_file.php" method="post" 
    enctype="multipart/form-data">
    <label for="file">Filename:</label>
    
    <input type="file" name="file" id="file" /> <br />
    <label for="name" >Name:</label>
    <input type="text" name="name" id="name" /><br />
    <label for="comments" >Comments:</label><br />
    <textarea name="comments" id="comments" ></textarea><br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    <img src="Picture3.jpg" id="Image4" alt="" align="top" border="0" width="500" height="375" style="position:absolute;left:1px;top:300px;width:500px;height:375px;z-index:7">
    <img src="Picture2.jpg" id="Image5" alt="" align="top" border="0" width="500" height="375" style="position:absolute;left:1px;top:666px;width:500px;height:375px;z-index:8">
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <!-- x10 Exchange code begin -->
    <!-- DO NOT ALTER THIS CODE! -->
    <script language="JavaScript"> 
    document.write('<s'+'cript language="JavaScript" src="http://www.x10exchange.com/work.php?n=118&size=1&j=1&c=&code='+new Date().getTime()+'"></s'+'cript>'); 
    </script> 
    <NOSCRIPT>
    <IFRAME SRC="http://www.x10exchange.com/work.php?n=118&size=1&c=" width=468 height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling="no"></IFRAME>
    </NOSCRIPT>
    <!-- x10 Exchange code end -->
    </font>
    </div>
    </body>
    </html>
    Oh and for that php script I forgot to say I added comments everywhere and tried to make it more readable so you can see whats going on, if you have an instant messenger it would be easier to work this out over that.
    Last edited by lszanto; 04-26-2008 at 06:03 AM.

  5. #5
    bigjoe4 is offline x10 Elder bigjoe4 is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    907

    Re: PHP message upload.

    I have uploaded the files and it does not work, it just sais "You have either left a field blank in the form or have uploaded the wrong kind of file, please go back and try again."
    Please visit my site: Circuit designer

  6. #6
    lszanto is offline x10Hosting Member lszanto is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    23

    Re: PHP message upload.

    Ah man i'm dumb, I think I found it, I just misspelt a word.
    PHP Code:

    <?php

    //Email function.
    function send_email($name$comment) {
        
    //Set vars.
        
    $to "person@email.com";
        
    $subject "Image uploaded by " $name;
        
    $message "An image has been uploaded, the details are below.\n\nName: " $name "\nComments: " $comments "\n\nThanks, your website";
        
    $from "From: <$name>";
        
        
    //Send email.
        
    mail($to$subject$message$from);
    }

    //Check for image types.
    if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 5000000) && isset($_POST['name']) && isset($_POST['comments'])) {
        
    //Check for an error.
        
    if ($_FILES["file"]["error"] > 0) {
            
    //If an error, tell the user.
            
    echo "Return Code: " $_FILES["file"]["error"] . "<br />";
        } else {
            
    //Show upload details.
            
    echo "Upload: " $_FILES["file"]["name"] . "<br />";
            echo 
    "Type: " $_FILES["file"]["type"] . "<br />";
            echo 
    "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo 
    "Temp file: " $_FILES["file"]["tmp_name"] . "<br />";
            
            
    //Check if the file exists.
            
    if (file_exists("upload/" $_FILES["file"]["name"])) {
                
    //If the file exists, tell the user.
                
    echo $_FILES["file"]["name"] . " already exists. ";
            } else {
                
    //Upload the image.
                
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" $_FILES["file"]["name"]);
                
    //Inform the user.
                
    echo "Stored in: " "folder/" $_FILES["file"]["name"];
                
                
    //Send the email.
                
    send_email($_POST['name'], $_POST['comments']);
            }
        }
        
    } else {
        
    //Tell the user file is invalid or they have left a field blank.
        
    echo "You have either left a field blank in the form or have uploaded the wrong kind of file, please go <a href=\"pictures.html\" >back</a> and try again.";
    }

    ?>

  7. #7
    bigjoe4 is offline x10 Elder bigjoe4 is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    907

    Re: PHP message upload.

    it works, I have sent you 1000 credits.
    Please visit my site: Circuit designer

  8. #8
    lszanto is offline x10Hosting Member lszanto is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    23

    Re: PHP message upload.

    Thankyou, glad I could help.

+ Reply to Thread

Similar Threads

  1. CRON Jobs and PHP
    By deadimp in forum Tutorials
    Replies: 14
    Last Post: 11-27-2008, 05:09 PM
  2. My 2cents on Ruby vs PHP.
    By jwillia in forum Programming Help
    Replies: 0
    Last Post: 03-15-2008, 11:18 PM
  3. How to protect images without htaccess using PHP
    By frznmnky in forum Tutorials
    Replies: 0
    Last Post: 12-26-2007, 11:51 AM
  4. Cambios IMPORTANTES en PHP.
    By Fedlerner in forum Noticias y Anuncios
    Replies: 1
    Last Post: 11-06-2007, 11:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers