Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<form method="post" action="myscript.php" enctype="multipart/form-data">
<input type="file" name="images">
</form>
function uploadFile() {
// import form data into local function
global $ulFile, $ulFile_name, $ulFile_type;
// check for form data
if (isset($ulFile) && $ulFile_name) {
// check uploaded file is one of supported types
if ($ulFile_type == "image/png" ||
$ulFile_type == "image/jpeg" ||
$ulFile_type == "image/pjpeg") {
$fn = getUniqueName($ulFile_name); // generate a unique file name
/* move file to the photo directory. Notice we now use move_uploaded_file
* instead of copy. It includes a check to make sure the file came from
* the right source, making it more secure
*/
if (move_uploaded_file($ulFile, PHOT_DIR."/$fn")) {
print "<p>$ulFile_name successfully uploaded</p>\n";
saveThumbnail($fn); // generate tumbnail image
} else {
print "<p>Oops! Couldn't upload $ulFile_name</p>\n";
unlink($ulFile); // remove temporary file
}
} else {
print "<p>Sorry, file type $ulFile_type not supported. Try a JPEG or PNG image.</p>\n";
unlink($ulFile); // remove temporary file
}
}
}
--------------------------------------------------------------------------------
and the form code
<?php
/* album.php - version 3
* .net magazine ([URL unfurl="true"]www.netmag.co.uk),[/URL] issue 83
* Matt Kynaston, 2001
* Distributed under the GNU Public License - [URL unfurl="true"]www.gnu.org/copyleft/gpl.html[/URL]
*
* The PHP Photo Album displays the contents of a thumbnail directory,
* linked to full size images in the photo directory. It gives the user
* the opportunity to upload their own photos to the album, automatically
* creating tumbnails.
*
* Requires PHP4 with the GD and ZLIB extensions installed (php_gd.dll and php_zlib.dll
* on Windows). These are available from the full download of PHP at [URL unfurl="true"]www.php.net[/URL]
* Modify your php.ini file (C:\WINDOWS\PHP.INI in Windows systems) to point at them
*/
/* constant declaration section
* change these to modify the album directories or image sizes
*/
define("NUM_COLS", 4); // number of columns in table
define("PHOT_DIR", "photos"); // photo directory, relative to this page
define("THUMB_DIR", "thumbs"); // thumbnail directory, relative to this page
define("MAX_XY", 150); // maximum width or height of thumbnail image
/* all the functions used on this page have been split off into a
* seperate file. The include statement below makes them available to this
* page.
*/
include("album_functions.php");
?>
<html>
<head>
<title>Photo Album</title>
<link href="album.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>PHP Photo Album</h1>
<h3>(final version)</h3>
<?php uploadFile() ?>
<form name="form1" method="post" action="<?php print $PHP_SELF?>" enctype="multipart/form-data">
<p>Add your own image to the album:<br>
<input type="file" name="ulFile">
<input type="hidden" name="MAX_FILE_SIZE" value="512000">
</p>
<p>
<input type="submit" name="Submit" value="Upload">
</p>
</form>
<p> </p>
<?php makeAlbumTable(); ?>
</body>
</html>