PHP can create the desired files using native PHP functions like fopen(), fwrite(), fclose(). Doing this when a button is clicked can be managed much like a form submittal. Instead of processing form fields, you create .vcf files.
Where is the card data coming from? If it’s from form fields, you’d just add the file writing process to the usual form handling procedure. If the card creation function is meant only for registered, logged in users, their usual user data could be used to create the card file. The default data can be had with get_userdata( get_current_user_id()). Other user data is likely saved in usermeta, which can be retrieved with get_user_meta().
What volume of .vcf files are you expecting? While it’s possible to store quite a few files in one folder, there is a limit. You may want to consider some sort of garbage collection routine that deletes older files. This can be done as a WP Cron task or a server Cron job.
It’s not even necessary to write to a file if its only use is for immediate download. PHP can send a file data stream directly to the client without needing to save the file on the server. It’s mainly a matter of sending the right header information prior to sending the data.
I am stuck in a problem while building a digital business Card on wordpress, Please help me out with this problem.
Problem I want to add an option of save the card means save the cotact details directly by just clicking/hiting that button in my digital business card, For that i also created one dedicated folder in my Database for vcf file with the name of Uploads and in this folder i also paste a php file for vcard after guidning by the chat support of hostinger but that only works for that particular vcf file whose name is mentioned in the php but also it is only downloadable not importable (means when we hit the downloaded vcf file then an message apperas Contact couldn’t import) and i want to add lots of vcf file so it means i need to add php files as well.
Solution Which I know of that problem
So to achieve this we need to add that vcf file in that upload folder, which i am doing, then we can create a link which is should be like that https://domainname/uploade/vcffilename.vcf. But unfortunatelly it is not happing through this link the coded vcf file available.
Can you please guide me what the thing i am missing here so that my vcf link works properly and i can also provide the save option.
Regards Vaibhav Narang
If you provide the correct file URL within an <a> tag, assuming the file exists and the folder/file permissions are correct, the browser will either open the file or offer a dialog to save it. You can style the link with CSS to look like a button if you prefer.
If a link is not working, either the URL is incorrect, or the file or folder permissions are incorrect.