Up-Loading Images:

objectives:

  • may not work in virtual hosts
upload.htm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>upload </title>
</head>
<body text="#000080" bgcolor="#F0FAFF">
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" size="30">
<input type="submit" value="Upload File" />
</form>
</body>
</html>

upload.php (code)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>upload </title>
</head>
<body text="#000080" bgcolor="#F0FAFF">
$_SERVER['DOCUMENT_ROOT']."/web_folder/web-subfolder/";
<?php
// Is the file there
if (isset($_FILES['file']) == false OR $_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) {
die('No files');
}
// No problems?
if ($_FILES['file']['error'] != UPLOAD_ERR_OK) {
die('Error occured during upload');
}
// Move file to our upload folder
$path = $_SERVER['DOCUMENT_ROOT']."/php5/tutorials_example/forms/upload_file/";
$newfile = $path . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $newfile);
die('Your file has been successfully uploaded.');
fclose($handle);
?>
</body>
</html>
 

Step :1

Step :2 Browse to the file.

Step 3: load the document

Step 3 (contd.); Note the list of files before uploading.
Step 4: Upload was successful.

Step 4 (Contd.):

Repeat with other file types like word document.
Loaded word document

upload was successful.

Note the document at the server end.
loading an image

file upload