Miscellaneous

  Home arrow Miscellaneous arrow Page 3 - Uploading Files with Forms and PHP
MISCELLANEOUS

Uploading Files with Forms and PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2003-09-28

    Table of Contents:
  • Uploading Files with Forms and PHP
  • PHP Code
  • Finishing it up

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Uploading Files with Forms and PHP - Finishing it up


    (Page 3 of 3 )

    The move_uploaded_file function takes two string arguments: the name of the temporary file and the destination. Note that the uploaded file will overwrite any pre-existing files so you should check first to see if a file of that same name already exists. Also ensure the directory to which the file will be copied has the appropriate permissions.

    <?php
    if (($_FILES["file"]["type"] == "image/gif") &amp;&amp;
    (
    $_FILES["file"]["size"] &lt15000)) {
      echo 
    "Return Code: " $_FILES["file"]["error"] . "&lt;br /&gt;";
      echo 
    "Uploading " $_FILES["file"]["name"];
      echo 
    " (" $_FILES["file"]["type"] . ", ";
      echo 
    ceil($_FILES["file"]["size"] / 1024) . " Kb).&lt;br /&gt;";

      if (
    file_exists("uploads/" $_FILES["file"]["name"])) {
        echo 
    $_FILES["file"]["name"] . " already exists.  ";
        echo 
    "Please delete the destination file and try again.";
      } else {
        
    move_uploaded_file($_FILES["file"]["tmp_name"], 
        
    "uploads/" $_FILES["file"]["name"]);
        echo 
    "File has been stored in your uploads directory.";
      }

    } else
      echo 
    "Sorry, we only accept .GIF images under 15Kb for upload.";
    ?>

    About the Author

    Timothy Boronczyk lives in Syracuse, NY, where he works as an E-Services Coordinator for a local credit union. He has a background in elementary education, over 5 years experience in web design and has written tutorials on web design, PHP, Ruby, XML and various other topics. His hobbies include photography and composing music.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap