+ 1

How do i store an image that was uploaded through a form , permanently on a page .

I understand that i have to use local storage but i dont know how to go about it? This is the important part of the code; <?php if(isset($_POST['submit'])){ $file = $_FILES['file']; $fileName = $_FILES['file']['name']; $fileTmpName = $_FILES['file']['tmp_name']; $fileSize = $_FILES['file']['size']; $fileError = $_FILES['file']['error']; $fileType = $_FILES['file']['type']; $fileExt = explode('.',$fileName); $fileActualExt = strtolower(end($fileExt)); $allowed = array('jpg' , 'jpeg' , 'png' , 'pdf'); if(in_array($fileActualExt,$allowed)){ if($fileError === 0){ if($fileSize<1000000){ $fileNameNew = uniqid('',true).".".$fileActualExt; $fileDestination = 'uploads/'.$fileNameNew; move_uploaded_file($fileTmpName, $fileDestination); }else{ echo "Your file is too big!"; } }else{ echo "There was an error uploading the file"; } }else{ echo "You cannot upload files of this type!"; } } ?> <a href=""><img src="<?php echo $fileDestination;?>" width="250" height="250"/></a>

14th Feb 2018, 7:20 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
4 Answers
+ 1
Does the scandir function permanently store the image on the page? as in when i reload the page, the image is still there.
14th Feb 2018, 7:36 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
+ 1
How do i rephrase this. My code works, i can add an image BUT i want to store the image permanently on the page so that when the page is reloaded , the image is still there because it is stored. Hence, the solution you gave me, does it solve the storage problem?
14th Feb 2018, 7:41 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
You can display all your images with scandir() function. http://php.net/manual/en/function.scandir.php $images = scandir("uploads"); for($a = 2; $a < count($images); $a++) { echo "<img src='uploads/" . $images[$a] . "' />"; } So you can see all your uploaded images on your page I hope that's what you meant
14th Feb 2018, 7:38 PM
Toni Isotalo
Toni Isotalo - avatar
0
So you meant that you want to write it into the php file?
14th Feb 2018, 7:40 PM
Toni Isotalo
Toni Isotalo - avatar