bertrc
I have this files but the images is not going in the folder imgs
ch4/views/imagesUploadForm.php
<?php
$info = "
<h1>Upload New jpg Images</h1>
<form method='post' action='imageslistindex.php?page=imagesUpload' enctype='multipart/form-data' >
<label>Find a jpg image to upload</label>
<input type='file' name='image-data' accept='image/jpeg'/>
<input type='submit' value='upload' name='new-image' />
</form>";
?>
ch4/imageslistindex.php
<?php
//complete code for index.php
$nav = "";
$info = "";
include_once "views/imageslistnavigation.php";
include_once "classes/Page_Data.class.php";
$pageData = new Page_Data();
$pageData->setTitle("Dynamic image gallery");
$pageData->setContent($nav);
$navigationIsClicked = isset($_GET['page']);
if ( $navigationIsClicked ) {
$fileToLoad = $_GET['page'];
} else {
$fileToLoad = "securelistgallery";
}
include_once "views/$fileToLoad.php";
$pageData->appendContent($info);
require "templates/page.php";
echo $page;
?>
ch4/views/imageslistnavigtion.php
<?php
$nav = "
<nav>
<a href='imagelistindex.php?page=securelistgallery'>Gallery</a>
<a href='imagelistindex.php?page=imageupload'>Upload new image</a>
</nav>
";
?>
ch4/classes/ImagesUploader.class.php
<?php
//complete code for classes/Uploader.class.php
require_once "views/checkImageFile.php";
class ImagesUploader {
private $filename;
private $fileData;
private $destination;
private $keyValue;
//declare a constructor method
public function __construct( string $key ) {
$this->keyValue = $key;
$this->filename = $_FILES[$key]['name'];
$this->fileData = $_FILES[$key]['tmp_name'];
}
public function saveIn( $folder ) {
$this->destination = $folder;
}
public function save(){
$variableName = $this->keyValue;
$tmp = $_FILES[$this->keyValue]['tmp_name'];
$folderIsWriteAble = is_writable( $this->destination );
$notValid = checkImageFile($tmp, $variableName);
//if( $folderIsWriteAble ){
if( !$notValid and $folderIsWriteAble) {
$name = "$this->destination/$this->filename";
$success = move_uploaded_file( $this->fileData, $name );
} else {
$success = false;
}
return $success;
}
}
?>
ch4/imageslistindex.php
<?php
//complete source code for views/upload.php
function upload(){
include_once "classes/ImagesUploader.class.php";
//image-data is the name attribute used in <input type='file' />
$uploader = new ImagesUploader( "image-data" );
$uploader->saveIn("imgs");
$fileUploaded = $uploader->save();
if ( $fileUploaded ) {
$out = "New file uploaded to Images Gallery";
} else {
$out = "Something went wrong file not uploaded to Images Gallery";
}
return $out;
}
$info = upload();