Before I give you this advice, keep in mind that it is US-centric and probably not applicable if you are applying to many international/European style programs where research effectively begins day 1 with no/limited coursework. There is no need to upload a writing sample unless the application specifically calls for it. Honestly, it is probably something that would be used as a means of exclusion rather than inclusion in candidate pools. Most adcoms probably only evaluate the writing sample in terms of your ability to meet a minimum threshold to communicate effectively and not in terms of academic or scholarly rigor. Thus, a bad writing sample will hurt you more than a good writing sample would help you.
In terms of being able to communicate scholarly ability, they will be looking for things like conference presentations (relatively uncommon for a PhD applicant) or publications/manuscripts under review (very rare for a PhD applicant) at high level scholarly outlets. What program areas are you applying to? Several big conference deadlines are coming up and it might be a good idea to submit it there so that you can list it on your CV as being under review/submitted for consideration.
Do not attach the writing sample to your SOP. If you are pretty confident that your writing sample will convey information about your scholarly aptitude above and beyond what your CV shows, then I think it would be a good idea to email the PhD program director and ask if this is something that they would like included in your application materials.