User Tools

Site Tools


file_storage

This is an old revision of the document!


File Storage

Almost all websites need to allow uploading files and tracking them. Sometimes you want to associate an image with a specific data row like a user image associated with user. Other times you may want to allow uploading multiple documents and/or images associated with a parent row of data.

Public versus Secure/Private

Some images uploaded need to be public so they can be used in lists. For example avatars or images associated with users will most likely need to be public so when showing users a list of all users they can see the images associated with everyone.

Other images or files need to be private or secure. For example if your website requires people to upload their driver's license you would not want that to be available to the public.

File Uploads

The Wizard's Toolkit library has a PHP function that works in conjunction with our JS function to make uploading a file easy. The /demo folder has several example files showing exactly how this is done. The PHP code requires pulling the data from the SQL table like this;

SELECT `FirstName`,`FilePath`,`NewFileName`
 FROM `wtkUsers`
WHERE `UID` = ?

Then the PHP code would simply be:

$pgHtm .= wtkFormFile('wtkUsers','FilePath','/imgs/user/','NewFileName','User Photo','m6 s12');

The parameter options for wtkFormFile are as follows;

function wtkFormFile($fncTable, $fncColPath, $fncFilePath, $fncFileName, $fncLabel = '', $fncColSize = 'm6 s12', $fncRefresh = '', $fncShowOneClickUpload = 'N', $fncAccept = 'accept="image/*"', $fncThumbnail = 'Y')
  • $fncTable name of data table
  • $fncColPath name of data column to hold path to image/file
  • $fncFilePath actual path on webserver
  • $fncFileName name of data column to hold new name of file uploaded
  • $fncLabel optionally passed to show as label; if not then uses $fncColName
  • $fncColSize MaterializeCSS column sizing - defaults to 'm6 s12'
  • $fncRefresh defaults to blank; set to image ID you want refreshed upon saving (by JS)
  • $fncShowOneClickUpload defaults to 'N' but if set to 'Y' then adds button to upload using AJAX without needing a 'Save' button
  • $fncAccept defaults to 'accept=“image/*”'; you can change this to other document filters like accept=“.pdf”
  • $fncThumbnail defaults to 'N'; if set to 'Y' then adds an <img id=“imgPreview” …> which will show a preview of images

More Coming Soon

More technical details will be added soon.

file_storage.1662334885.txt.gz · Last modified: 2022/09/04 23:41 by wtkadmin