transferring photo file name from text area to image address

Problems with the Windows version of XAMPP, questions, comments, and anything related.

transferring photo file name from text area to image address

Postby MikeSiencyn » 23. April 2021 11:32

Hi folks
This is the continuing story of building a website for my wife's vintage shop.
First, many, many thanks to Nobbie for helping me to speed up the loading of the web pages - it worked, 6 seconds became a fraction of a second!
Now I'm trying to make a user friendly method for my wife to upload her photos.
I've got to a point where I know what I want to do but don't know how to do it.
In the following code:
<body>
<h1>Photo Test</h1>
<div id="images">
<textarea id="photo1" name="photo1" rows="1" cols="48"></textarea>
<div id="image1" class="image"><img src="http://localhost/Number21AWebsiteEjercicio/photos/$photo1" alt="photo 1">
</div>
</div>
</body>
I want to get the photo file name my wife pastes in the textarea to appear as the value of $photo1 (don't know if I've expressed this variable properly).
I would be very grateful for some help on this.
Many thanks
Mike
MikeSiencyn
 
Posts: 24
Joined: 02. February 2021 15:41
XAMPP version: 3.2.4
Operating System: Windows10

Re: transferring photo file name from text area to image add

Postby Nobbie » 23. April 2021 18:29

You are going in the wrong direction, for file uploads (including photos) HTML Forms have the special input type "file". Here is a link to one of many tutorials, how to work with type="file", especially how to handle it in PHP:

https://www.w3schools.com/php/php_file_upload.asp

There is no need for textareas including any filename, the type "file" gives you a listbox of local files and also gives you all information (including filename) about the file which has been choosen and uploaded by the user.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: transferring photo file name from text area to image add

Postby Nobbie » 24. April 2021 13:23

Actually, if you want to use PHP to insert the photo1 name in the link, you need to send the form to your server (as PHP is executed on your server, not on your local PC) and finally PHP hast to respond with the appropriate HTML Code to show the photo in an HTML Document.

You could do it with JavaScript instead, so you dont need to send the textarea to your server, but then you have to learn JavaScript as well. I dont get the idea of your code, as already said above, i think you are on the wrong way. I also do not understand, why you link the photo to localhost, you need a local webserver for that, but actually you do not need a local webserver for watching local pictures in a browser. Thats all quite confusing and i dont get the idea.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: transferring photo file name from text area to image add

Postby MikeSiencyn » 25. April 2021 20:02

Thanks Nobbie
I thought I might be a bit lost. I have been using php and what you've said has really helped.
All the best
Mike
MikeSiencyn
 
Posts: 24
Joined: 02. February 2021 15:41
XAMPP version: 3.2.4
Operating System: Windows10


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 139 guests