| 4:33 pm on Sep 15, 2002 (gmt 0)|
Are you really trying to 'upload' a file, or just some text/etc to a record?
Check out the UPDATE command. (I think that's right ;))
| 8:37 pm on Sep 15, 2002 (gmt 0)|
Yep, I am trying to "upload" an image to a BLOB field. I can upload the image , but not to the correct record at the moment.
I shall check out "upload", thanks.
| 8:46 pm on Sep 15, 2002 (gmt 0)|
You need to specify which record (clearly ;))
Why not post the code, it's a bit tricky to guess what's going on....
| 8:54 pm on Sep 15, 2002 (gmt 0)|
Bit difficult to post the code at the moment as I am at work and switching between two machines! I have used a url variable from one page to the next to select the correct record but I can't figure how to upload a file to that record using "file" as the attribute for a form. I think I will post the code tomorrow if you can still help!
| 9:01 pm on Sep 15, 2002 (gmt 0)|
Yeah, I've got email notification on this thread.. no worries.
| 10:18 am on Sep 16, 2002 (gmt 0)|
Sucess at last! I have now managed to get the upload into the correct record and into the blob column but it is just showing text ie. the path to the file instead of the actual file.
Do I have to escape some of the characters or is it a case of actually writing the file to the database. I have looked for some scripts to give me some hints and one has the following:
$data = addslashes(fread(fopen($form_data, "rb"), filesize($form_data)))
Not sure what the "b" is for in the file mode?
| 10:33 am on Sep 16, 2002 (gmt 0)|
|Not sure what the "b" is for in the file mode? |
binary - useful only on systems which differentiate between binary and text files such as Windows
| 10:40 am on Sep 16, 2002 (gmt 0)|
|but it is just showing text ie. the path to the file instead of the actual file |
$_FILES just contains infos about the uploaded file. $_FILES['userfile']['tmp_name'] will give you the name of the temporary file on the server. To store the file to the database you have to open it and read it as suggested by the little code snippet you included in your post.
| 11:03 am on Sep 16, 2002 (gmt 0)|
Thank you very much. I couldn' find the "b" in either of my php books. The fread/fopen is the clue. I shall have another go. By the way, is there a problem with storing binary info in MySql? This is for a customer to upload his images and saves me having to instruct him how to upload to a separate directory.
| 5:28 pm on Sep 16, 2002 (gmt 0)|
Why don't you just store the images in a designated directory and then store the path in the DB? Is it absolutely necessary to store the whole image in the DB?
| 8:10 pm on Sep 16, 2002 (gmt 0)|
The only reason for storing in the database was to allow the customer an easy way to update. I suppose I could set up a file upload page and then put the path in the database along with the rest of the details. In a form, is there a means to hide the path and then add the file to it perhaps by a variable? It just means that there has to be two operations for each change. I don't know if it wold be a good idea to allow a user access to the directories for deletion etc?
| 8:45 pm on Sep 16, 2002 (gmt 0)|
You can have the script do everything and they wouldn't see anything exactly the same as if it was dumping into the DB. I was just figuring it would be easier on the DB. I hate putting images into a db unless they are tiny. I prefer to have a dir for them and just build the path with the script and put that into the db.
You can just hard code the path into the script. Have a designated dir for the uploaded images or something.
>>user access to the directories
The scipt would have the access, not the user.