coolphpdude Posted April 7, 2008 Share Posted April 7, 2008 Hi there, Ive got my upload code working spot on. you choose the file you want to upload and it sends it to my hosting, if the file exists it randomly renames the file and then uploads it. The target path is stored in a field on my database so for example user fred uploads histext.doc the uploaded field on my database would be '/userfiles/fred/histext.doc'! However, I only want the user to be able to upload 1 single file, if they upload another file it should replace the existing file. so basically i need to know how to delete the existing file. so fred uploads newtext.doc, histext.doc is deleted from my hosting, newtext.doc is uploaded and the new target path is updated in my database. any ideas?? Link to comment https://forums.phpfreaks.com/topic/99970-uploading-a-file-and-removing-a-file/ Share on other sites More sharing options...
cooldude832 Posted April 7, 2008 Share Posted April 7, 2008 well first your database shouldn't be a .doc file but a mysql database as it is standard in php. Then when u have a standard database + user login system you can simply store files with association to a given username. i.e I upload data_07.doc my userid is 2543 so it because 2543.doc I upload later data_023.doc it uses move_uploaded_file and names it 2543.doc that simple Link to comment https://forums.phpfreaks.com/topic/99970-uploading-a-file-and-removing-a-file/#findComment-511196 Share on other sites More sharing options...
coolphpdude Posted April 7, 2008 Author Share Posted April 7, 2008 sorry i think you have misunderstand, i meant the user (fred in this case) has uploaded a document. I am using a MySQL database with various tables. One table within this database is a user table consisting of basically these 2 fields 'username' and 'uploaded_file'. Fred logs in to my site, uploads 'histext.doc', the file is sent to my hosting and the path is added to freds 'uploaded_file' field. If fred uploads a second document i want the original document to be deleted from my web hosting and replaced with the second file. I know how to move the file to the hosting, i also now how to upload the field on the database, i just need to know how to remove the existing file. I am saying the user will only be able to have one uploaded file for the purpose of the example to make things less complicated, the user will in fact be able to upload as many files as necessary, therefore renaming the file to the users username would not be feasable. any help is much appreciated Link to comment https://forums.phpfreaks.com/topic/99970-uploading-a-file-and-removing-a-file/#findComment-511203 Share on other sites More sharing options...
coolphpdude Posted April 7, 2008 Author Share Posted April 7, 2008 to put it in the most simplest of terms, how do i execute a command that will delete a file from my host? Link to comment https://forums.phpfreaks.com/topic/99970-uploading-a-file-and-removing-a-file/#findComment-511226 Share on other sites More sharing options...
cooldude832 Posted April 7, 2008 Share Posted April 7, 2008 to put it in the most simplest of terms, how do i execute a command that will delete a file from my host? look up unlink Link to comment https://forums.phpfreaks.com/topic/99970-uploading-a-file-and-removing-a-file/#findComment-511299 Share on other sites More sharing options...
coolphpdude Posted April 8, 2008 Author Share Posted April 8, 2008 that worked a treat cheers! bring back 'solved'!! Link to comment https://forums.phpfreaks.com/topic/99970-uploading-a-file-and-removing-a-file/#findComment-511885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.