0

im working on a basic image upload system. So far im using the class_upload.php from verot which is working great.

I have basic-auth protected the directory where the Images are safed for now.

However i would like to display the recently uploaded image on the upload-page.

This should be simple i thought using this code

 if ($imageFileType == "jpg") {
     echo "<img src=https://USER:PASS@mywebsite.de/uploads/" . $bildname . ".jpg> </img>"; 
 } elseif ($imageFileType == "jpeg"){
     echo "<img src=https://USER:PASS@mywebsite.de/uploads/" . $bildname . ".jpeg> </img>"; 
 } elseif ($imageFileType == "png") {
     echo "<img src=https://USER:PASS@mywebsite.de/uploads/" . $bildname . ".png> </img>";
 } elseif ($imageFileType == "gif") {
     echo "<img src=https://USER:PASS@mywebsite.de/uploads/" . $bildname . ".gif> </img>";  
}

Where $bildname is obviously the (correct) name of the new file. However when i upload an image, it only show that basic "image icon" when there couldnt be an propper image displayed.

Using the link "https://USER:PASS@mywebsite.de/....." directly on the webbrowser, opens the image though.

Can anyone recommend a fix or another work around to my problem?

1Day2Die
  • 29
  • 9

2 Answers2

0

What you are doing is not safe! But Based on the limited information and trying out your code the only issue I can find is that you aren't echoing the child quotes around the src='';

try this it might help and the reason for it working correctly if it does is because instead of echoing valid html its echoing a broken html sequence as a string instead of html tag.

If you can provide more information (is it echoing anything a blob of data or other error info) It would be very useful.

Try changing each line to look like this:

if ($imageFileType == "jpg") {
 echo "<img src='https://USER:PASS@mywebsite.de/uploads/" . $bildname . ".jpg'> </img>";} 

your outputed data should be like this:

<img src='https://USER:PASS@mywebsite.de/uploads/file.gif'> </img>

what you should do instead is save that image either to a database as a blob/cache it to redis and call from there OR you can save it to a normal directory that only the server can access and echo the image file from that directory.

  • Thanks for the tipps. This however will probably not be done yet. I want to keep it simple for now. Oh man, i just realised ive forgotten the " ' " signs. The HTML output is following ` ` however, It still only shows that little "missing picture" icon. When clicking the link however the correct picture is shown. How can this be? To clarify, i added screenshots of the upload page, and the sourcecode https://imgur.com/IaLSmHx https://imgur.com/cXvwb0s I hope this helps – 1Day2Die Oct 16 '19 at 12:52
0

This was easily made by creating a new get_images.php file which will open the Image using fopen() and fpasssthru()

then in the tag you can set src="get_image.php"

1Day2Die
  • 29
  • 9