Welcome Guest, Not a member yet? Register   Sign In
How to do an image upload like Wordpress (and other CMS's) do
#1

[eluser]Gwarrior[/eluser]
What I mean by that is, how can I do an upload then inject the upload path into the textarea or text field? I can do the upload portion and get the path, it's just the injection part that I am having trouble with. Is it Javascript or what?

Thanks in advance!
#2

[eluser]BrianDHall[/eluser]
I'm afraid I'm not entirely sure what you want to achieve. If you want to allow the user to specify the directory to upload to, then that is just another field that when a file is uploaded gets used to specify where the file is moved to from the temporary file upload directory that PHP determines.

Otherwise I'm not really sure the behavior you speak of.
#3

[eluser]Gwarrior[/eluser]
I'm fine with practically everything concerning CodeIgniter and uploading images and grabbing paths and what not. My question is, how do I take that path after I upload it, and inject it right into a textarea.

Example:
Code:
<textarea name="field_1"><img src="[path pulled after uploading" /></textarea>

Where the entire <img> tag was not there until I uploaded and hit a button "Insert into Text field".

I know this is Javascript, but how is something like this achieved?

Thanks.
#4

[eluser]BrianDHall[/eluser]
Ooo! Well here you go for the adding to text area javascript (one way to do it, anyway): http://www.mediacollege.com/internet/jav...-text.html

The question is then, how to get the path to your javascript function so it knows what to add to the text area. The easy way is if you are doing your upload the 'classic' way where the page as a whole is refreshed once the file is uploaded - then in your controller you just get the path to the uploaded file and pass it to your javascript.

If you want to do it all without a page refresh, that is a bit more complex javascript. You would want your javascript file uploader to upload the file, then get a response from the server of the path that was uploaded to. The javascript function would fire on file upload complete and read the response and set it as a variable that would then be available when the person clicked "insert into text field".




Theme © iAndrew 2016 - Forum software by © MyBB