Html Posted April 11, 2020 Share Posted April 11, 2020 Hi, Where does the image uploaded here in this, display once it has been uploaded to a directory <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP File Upload</title> </head> <body> <form method="POST" action="<?php $_SERVER[ 'PHP_SELF' ] ?>" enctype="multipart/form-data"> Select an image to upload : <input type="file" name="image" > <input type="submit" value="Upload Image" > </form> <?php if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) { $name = $_FILES[ 'image' ][ 'name' ] ; $temp = $_FILES[ 'image' ][ 'tmp_name' ] ; $size = $_FILES[ 'image' ][ 'size' ] ; $ext = pathinfo( $name , PATHINFO_EXTENSION ) ; $ext = strtolower( $ext ) ; if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' ) { echo 'Format must be PNG, JPG, or GIF' ; exit() ; } if( $size > 512000) { echo 'File size must not exceed 500Kb' ; exit() ; } if( file_exists( $name ) ) { echo 'File '.$name.' already uploaded' ; exit() ; } try { move_uploaded_file( $temp , $name ) ; echo 'File uploaded : '.$name ; echo '<br><img src="'.$name.'">' ; } catch( Exception $e ) { echo 'File upload failed!' ; } } ?> </body> </html> I have something a little similar, which was probably helped by a few on here last year. That works as is, but I'm curious to know where exactly, the image is temporarily displayed in this code. While this code is structured for uploading to the main directory, and not a specific folder, it does display the image. { move_uploaded_file( $temp , $name ) ; echo 'File uploaded : '.$name ; echo '<br><img src="'.$name.'">' ; } Could be this? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 11, 2020 Share Posted April 11, 2020 Usually a tmp folder is set in php.ini, alongside max file size and others. Use phpinfo(); And find tmp folder location. Link to comment Share on other sites More sharing options...
Html Posted April 11, 2020 Author Share Posted April 11, 2020 Right, so the image is stored then in $temp, this value. upload_tmp_dir Directive /tmp So this is local value, /tmp And Master value Link to comment Share on other sites More sharing options...
dsonesuk Posted April 11, 2020 Share Posted April 11, 2020 It is giving a temp name such as tmp000, which is stored in the set directory in php.ini, this tmp name is accessed by $temp = $_FILES[ 'image' ][ 'tmp_name' ] ; This can then be checked if it is valid, it can then attempt to move the temp file, to a specific destination with its original name from $name = $_FILES[ 'image' ][ 'name' ] ; Or modified name with time stamp for instance, or completely different name. Link to comment Share on other sites More sharing options...
Html Posted April 11, 2020 Author Share Posted April 11, 2020 The set directory, being the upload_tmp one. So what about simply display images that have been sent to a folder in the directory, how can the images simply be displayed on a page, they'd simply be listed as a row going down, I am guessing without any CSS. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 11, 2020 Share Posted April 11, 2020 You can look in folder for all files of a specific ext/s and then display them by looping through them getting file name then use that filename for src, when creating img tag. Just google search "loop through image files in directory php" Link to comment Share on other sites More sharing options...
Html Posted April 13, 2020 Author Share Posted April 13, 2020 I searched on bing. <?php $fileList = glob('test/*'); foreach($fileList as $filename){ //Use the is_file function to make sure that it is not a directory. if(is_file($filename)){ echo $filename, '<br>'; } } https://thisinterestsme.com/php-list-all-files-in-a-directory/ Link to comment Share on other sites More sharing options...
Ingolme Posted April 13, 2020 Share Posted April 13, 2020 I don't know why so many people want to use glob(). Most of the time there is no need. scandir() is more efficient (though you have to add a bit of code to filter out "." and ".." from the directory list) Link to comment Share on other sites More sharing options...
Html Posted April 14, 2020 Author Share Posted April 14, 2020 I don't know, I just watched a clip the other day by Eli the computer guy, and then posted here for some pointers. Link to comment Share on other sites More sharing options...
Alexander Yeshua Posted April 16, 2020 Share Posted April 16, 2020 (edited) why not? FOR IMAGE BROWSING, DAMN, THAT WAS LONG <!DOCTYPE HTM> <head> <title>PHP File Upload</title> </head> <body> <?php> <input aria-label="Add Photo or Video" accept="video/*, video/x-m4v, video/webm, video/x-ms-wmv, video/x-msvideo, video/3gpp, video/flv, video/x-flv, video/mp4, video/quicktime, video/mpeg, video/ogv, .ts, .mkv, image/*, image/heic, image/heif" multiple="" display="inline" role="button" tabindex="0" type="file" class="_n _5f0v" id="js_bj" style="user-select: auto;" </?> </body> </htm> </!DOCTYPE htm> also, just use script, start that: php.opendir.exe PHP.OPENDIR.exe Edited April 16, 2020 by Alexander Yeshua Link to comment Share on other sites More sharing options...
Alexander Yeshua Posted April 16, 2020 Share Posted April 16, 2020 (edited) On 4/13/2020 at 10:48 PM, Html said: I searched on bing. <?php $fileList = glob('test/*'); foreach($fileList as $filename){ //Use the is_file function to make sure that it is not a directory. if(is_file($filename)){ echo $filename, '<br>'; } } https://thisinterestsme.com/php-list-all-files-in-a-directory/ wrong, who need <?php> it just webconfig, not a greate writing for web management folder contain webconfig Edited April 16, 2020 by Alexander Yeshua Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now