How to Upload a PHP Image File
- 1). Launch the editor and type the following to create the form:
<form enctype="multipart/form-data" action="upload_imagefile.php" method="POST">
Choose Photo: <input name="imagefile" type="file" /><br />
<input type="submit" value="Upload Image" />
</form>
Save the file as "upload_image.html." - 2). Create the PHP file used in the form action attribute by typing the following into a new file:
<?php
$ path = "images/";
$path = $path . basename( $_FILES['imagefile']['name']);
if(move_uploaded_file($_FILES['imagefile']['tmp_name'], $path)) {
echo "Success uploading ". basename( $_FILES['imagefile']['name']);
} else{
echo "Error when uploading the image.";
}
?>
Save the file as "upload_imagefile.php." - 3). Transfer the two files to your server. Test the form by navigating to your form page online.