Jump to content

moving files as blobs to mysql database


shaddf

Recommended Posts

Is there a way to move the file contents to Mysql database and sae as blob 

without using the fileInput.

 

I have read through the uploading way .

 

but now here is a situation where The script it'self has to copy the file to a database before it can be deleted from source folder.

Why ? incase of power failure and file has failed to be copied using rename(), an original  copy is in the database waiting to replace it in the intended destination folder later.

 

you realise in this case  I cannot  show the fileInput form.

How can I go about this??

can file_get_contents() be used to upload the file to mysql as blob?

Link to comment
Share on other sites

If this mystery application can do that then why can it not change the file which holds links to the source.

file_get_contents() can grab all the data from a file - yes. Then you can take that string, in memory, and put it wherever you want.

but it turns it to a string and in my database i have a blob field should i use text for it:

Also incase i had a pdf file, how am I supposed to save it  back to the destination folder in its original form after I have put it as string in my database

Link to comment
Share on other sites

shaddf, what is your actual task? Forget about this weird power failure stuff (WTF?), and just tell us what you need to do.

 

In your previous thread, you said you want to move files from any directory to another. Then rename() is the answer, plain and simple.

save files as blobs  from folder into database. is this code safer- am I on right track?? how can I apply rename() and test if it has succeeded:

$temp_file=file_get_contents("./jaen/pierre.pdf");

if(is_uploaded_file($temp_file))

and file_put_contents("./jonah/pierre.pdf",$temp_file)){//mysql to insert here

insert into base(data)values($temp_file);

}

Edited by shaddf
Link to comment
Share on other sites

Why would one want to store a distinct file inside a database table?  Afterall it is a stand-alone piece of information that, given a proper name, is easily identified, or if linked to a table that stores attributes about the file, can easily be located and retrieved.  There is no need to have the overhead of storing it and retrieving if from MySQL. 

 

Create a folder and create a naming structure and upload the files to that place and save it with a name that matches your defined pattern.  Should you need to have other characteristics about the file saved, then save them along with the file's name in a db table. 

 

If backup is your concern, then make a backup folder - either on the same system or on another.

Link to comment
Share on other sites

Why would one want to store a distinct file inside a database table?  Afterall it is a stand-alone piece of information that, given a proper name, is easily identified, or if linked to a table that stores attributes about the file, can easily be located and retrieved.  There is no need to have the overhead of storing it and retrieving if from MySQL. 

 

Create a folder and create a naming structure and upload the files to that place and save it with a name that matches your defined pattern.  Should you need to have other characteristics about the file saved, then save them along with the file's name in a db table. 

 

If backup is your concern, then make a backup folder - either on the same system or on another.

Thanks for the back up folder option.I'll consider it next time i try out things.

but in a system with very limited resources and the fact that I only want this file not to be overwritten incase of another upload  to the source folder and I only need it to be inside the database for a limited period and must be deleted if indeed a back up has been successfully made in the back up folder(intended destination).

 

task:delete attributes about the file from   table that stores them,insert these in backuptable ,get the file from source,temporarilty store it in db as blob .If copy to destination is done ,delete ffrom temp table .

Edited by shaddf
Link to comment
Share on other sites

It might actually be a good idea to sit down for a couple of days, figure out what your task is and then come back with a coherent problem description.

 

You keep telling us about BLOBs and databases, but that's not the task. It's your personal approach to the task (which could be completely wrong). Do you understand the difference? If you want us to help you, then we need to know the task, because that's the only way to figure out the right approach.

 

It seems what you actually want is move an uploaded file to a target destination while preventing name collisions. So is that the task?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.