Jump to content

uploading a file and removing a file


coolphpdude

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.