+ 1

display thumbnails of products on shop page.

My code has many lines, hence im not going to paste everything , just the important parts. I dont feel confident as to the way i achieved the task of displaying the thumbnail on the shop page. Hence , can someone let me know if how i did what i did is okay or not? I have a simple form : <center> <form method="POST" action="" enctype="multipart/form-data"> <center> <label>Thumbnail:</label><br><input type="file" name="thumbnail"><br><br> <input type="submit" name="submitThumbnail" value="upload thumbnail" formaction="shop.php"> </form> Then i have the following php in my shop page: <?php if(isset($_POST['submitThumbnail'])){ $file = $_FILES['thumbnail']; $fileName = $_FILES['thumbnail']['name']; $fileTmpName = $_FILES['thumbnail']['tmp_name']; $fileSize = $_FILES['thumbnail']['size']; $fileError = $_FILES['thumbnail']['error']; $fileType = $_FILES['thumbnail']['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!"; } } ?> <?php $myFile = fopen('shop.php','a+'); //open shop file and allows me to add code to it through php $newsneakerImage = "<a"." "."href='https://www.sololearn.com/Discuss?ordering=MostRecent'>"."<img"." "."id=newSneaker"." "."src=".$fileDestination." "."height=250"." "."width=250>"."</a>"; fwrite($myFile,$newsneakerImage); fclose($myFile); ?> I just want to add, the code does display the images but its has some defects which i am looking into solve with jquery etc. Is my code okay?

17th Feb 2018, 6:40 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
1 Réponse
+ 1
Could you publish the code on the Code Editor so we see how it runs??
4th Apr 2018, 3:48 AM
King Emma 👑
King Emma 👑 - avatar