Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Mike Wilson www.whisperingwind.co.uk

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Very simple php file upload

I think this is the minimum necessary to upload a file in php. First, the form, index.php:

<form enctype="multipart/form-data" action="upload.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="512000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>


Next, the php to accept the file, upload.php

<?php

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo "<p>";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Upload failed";
}

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

?> 

Basic ant script with vim & jikes

Apache ant build XML. This will use jikes in place of javac. Any compiler error output is formatted so that vim can parse it.

ant is a modern alternative to make. The build script is an XML file. It works particularly well with java. Download it for free from the Apache ant site. Most people find ant a lot nicer to live with than make.

<?xml version="1.0"?>

<project name="Hello" default="compile" basedir=".">
  <property name="name" value="Hello"/>
  <property name="version" value="1.0"/>

  <!-- Project directories.
  -->

  <property name="build" value="build"/>
  <property name="dist" value="dist"/>
  <property name="src" value="src"/>

  <!-- Compiler directives.
  -->

  <property name="optimize" value="off"/>
  <property name="deprecation" value="on"/>
  <property name="debug" value="on"/>

  <property name="build.compiler" value="jikes"/>
  <property name="build.compiler.emacs" value="true"/>

  <target name="init">
    <tstamp/>
    <mkdir dir="${build}"/>
  </target>

  <!-- Compile all the .java files from the source directory into
       the build directory.
  -->

  <target name="compile" depends="init">
    <javac srcdir="${src}" destdir="${build}" includes="**/*.java"
      debug="${debug}" deprecation="${deprecation}" optimize="${optimize}">
    </javac>
  </target>

  <target name="clean" depends="init">
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>

  <target name="test" depends="compile">
    <java classname="HelloWorld" fork="yes">
      <classpath>
        <pathelement location="${build}"/>
      </classpath>
    </java>
  </target>
</project>
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS