hello everybody...i would like to create a place where someone can login and upload or find and update a file(.doc). I can work with databases a little but I ve never actually used files. Please help :bigyello:
Printable View
hello everybody...i would like to create a place where someone can login and upload or find and update a file(.doc). I can work with databases a little but I ve never actually used files. Please help :bigyello:
update in real-time? or just upload a file over an existing one? I've looked around a bit, but creating an actual rich-text formatted document file seems impossible. However, there are some workarounds. You can create an HTML file and save it server-side with a ".doc" filename, and this will load fine in Microsoft Word, although you MIGHT have some trouble loading remote images. With the basics, it's pretty simple, but I'm not completely sure what you're looking to do.. so I will just give you some examples of opening/editing files and give you some PHP manual links.
First of all, for an easy walk-through on how to handle file uploads, click here. It has basically anything and everything you will need to upload a file to a webserver.
Now, if you don't already know how to open/edit files, here's some examples:
For more on fopen() and the other attributes you can use with it aside from "r", click here.PHP Code:<?php
//let's open somefile.doc
$fo = fopen('somefile.doc', 'r'); //r means READ-ONLY, using this parameter means you cannot edit this file
//we reference the file we want to open by using $fo,
// -> then choose how much we want to read of the file in bytes
// -> (in this case, filesize() is the entire file)
$read = fread($fo, filesize('somedoc.doc'));
fclose($fo); //we close the file
echo $read; //print out the file
/***************
* Much easier way to open an entire file, just for reading
***************/
$read = file_get_contents('somedoc.doc');
echo $read;
//this does the exact same as above, but in 2 lines. using fopen() is still helpful if you want to create or edit files though.
?>
A basic rundown of what you might want to do is as follows: you'd have a database that had a table of users, and possibly even a table of permissions for each file (depending on if you want that or not), to decide which users can read and/or edit different files, and maybe a field in their user table that tells whether or not they can create/upload or whatever. this is not needed, but depending on what you're doing, you might want some users to just have the ability to read/edit and some just the ability to upload, or you might have a whole slew of users and you don't want one user having the ability to edit another users' files. you can use a database to organize all of that stuff. aside from that, the rest is just getting file names and printing them into a textbox that a user can then edit, and when they submit, you just open that file and write over the old file contents.
I did a quick search on Google to see if there was anything that created document files and didn't really come up with much, aside from things I've mentioned already (although, I didn't look for long). I've never tried actually writing a Microsoft Word document using PHP, and I have my doubts about it all if you're actually trying to replicate the 'rich text' format. I think on a Windows server you might be able to use COM objects to help create one (although I have no idea). Like I said before, there's always workarounds like using HTML to format the doc file, which Microsoft Word can read fine. If a user downloaded, edited it, and re-uploaded it though, I don't know if Microsoft Word would reformat it as a document file or keep the HTML. If it didn't keep the HTML, then you'd probably be in trouble after that. However, if you're planning on having some type of "WYSIWYG" editor, like many forums have today, you should look into the things they're using (I don't know offhand, sorry).
Personally, I would stay away from having to format doc files at all if you could.
hope that helps a little.
Thanks a lot Kows I ll try that as soon as I get some time.
Regards :wave: