PHP Project (Simple) – Image Upload App

Previous Classes in Series:

  1. PHP Project (Simple) – Dynamic Photo Gallery Stream
  2. PHP Project (Simple) – Dynamic Photo Gallery


  • Basic LAMP, or Web Server Administration 
    • Verify pictures and folder have READ/WRITE permission for OTHER
  • Basic PHP
  • Basic HTML




LAMP Server

  • Create a “pics” directory in the Public Web Directory (/var/www/html)
  • Verify pictures and folder have at least a rw- permission.


  • Location on demo system: /etc/php/7.2/apache2/php.ini
  • Set File Uploads to: file_uploads = On



$saveDir = "./pics/";
$saveFile = $saveDir.basename($_FILES['fileToUpload']['name']);

if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $saveFile)){
	echo "<h1>Picture Uploaded</h1><br>".$_FILES['fileToUpload']['name']." was saved<br>";
	echo "<img src='".$saveFile."'><br><br>";
} else {
	echo "Upload Did Not Work<a href='./index.php'> Go Back</a>";

echo "<h3>Diagnostic Info:</h3>";
echo "<br>Tmp File Name: ".$_FILES['fileToUpload']['tmp_name']."<br>";
echo "saveFile Variable Valuable: ".$saveFile;

<h1><a href="./index.php">Back to Gallery</a></h1> 



<form action="upload.php" method="post" enctype="multipart/form-data">

Image you want to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit">


Be the first to comment

Leave a Reply