A global chmod 777 is always a bad idea and ill-advised. To achieve 755 (drwxr-xr-x) on directories and 644 (-rw-r--r--) on files recursively use
chmod -R a-x,u=rwX,go=rX /path-to-piwigo
However, if the files are owned by a different ssh/ftp user than the webserver user and shall be upgradable/writable by the webserver then it should probably be 775 and 664 instead. So
chmod -R a-x,ug=rwX,o=rX /path-to-piwigo
Giving "other" (than owner user and group) write permissions is never a good idea unless it's a weird server setup. And executable bits on general files is completely useless if not dangerous.
If the web server user is owner then even read permissions for other may not be needed, so this for 750/640 could be sufficient
chmod -R a-x,u=rwX,g=rX,o= /path-to-piwigo
Similar if web server user is in group, for 770/660
#chmod -R a-x,ug=rwX,o= /path-to-piwigo
Additionally, if you want to use some tools coming with Piwigo, after that global chmod you may want to give them executable permissions again like
chmod ug+x /path-to-piwigo/tools/*.{pl,sh}