05-17-2017, 12:10 PM
hey, thought i'd implement a file uploader, mainly for images but other files too, form uploads image to directory on server, in my case users/uploads/avatar . you can then either save the filename or full file path to the database, in my case i added a row to the table called avatar. here it goes:
the files we need are:
patch-4.2.6-uploads.php - place somewhere so you can navigate to it in the browser within userspice, maybe root
class.upload.php - place in users/classes/
uploads.php - place in users/includes/
patch-4.2.6-uploads.php: navigate to this in browser, it will magically add the required db row to tablehttps://pastebin.com/RXJ9BxTp
class.upload.php: best left untouched
https://pastebin.com/DpKmdXex
uploads.php: adapt to your needs-change things like image types, locations, db insertion etc
https://pastebin.com/iLKrM1J8
Next we need the form: adapt to your needs
https://pastebin.com/ZJ353CHa
heres how the form looks:
https://pasteboard.co/7nRsmlvAa.png
you could go one step further and upload without page refresh using ajax as snippet below, just need a way to refresh the image preview otherwise page refresh is required.
https://pastebin.com/BjDfdare
Code:
profiles
the files we need are:
patch-4.2.6-uploads.php - place somewhere so you can navigate to it in the browser within userspice, maybe root
class.upload.php - place in users/classes/
uploads.php - place in users/includes/
patch-4.2.6-uploads.php: navigate to this in browser, it will magically add the required db row to table
Code:
profiles
class.upload.php: best left untouched
https://pastebin.com/DpKmdXex
uploads.php: adapt to your needs-change things like image types, locations, db insertion etc
https://pastebin.com/iLKrM1J8
Next we need the form: adapt to your needs
https://pastebin.com/ZJ353CHa
heres how the form looks:
https://pasteboard.co/7nRsmlvAa.png
you could go one step further and upload without page refresh using ajax as snippet below, just need a way to refresh the image preview otherwise page refresh is required.
https://pastebin.com/BjDfdare