shaddf Posted November 14, 2015 Share Posted November 14, 2015 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? Quote Link to comment Share on other sites More sharing options...
hansford Posted November 14, 2015 Share Posted November 14, 2015 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. Quote Link to comment Share on other sites More sharing options...
shaddf Posted November 14, 2015 Author Share Posted November 14, 2015 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 14, 2015 Share Posted November 14, 2015 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. Quote Link to comment Share on other sites More sharing options...
shaddf Posted November 15, 2015 Author Share Posted November 15, 2015 (edited) 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 November 15, 2015 by shaddf Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 15, 2015 Share Posted November 15, 2015 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. Quote Link to comment Share on other sites More sharing options...
shaddf Posted November 15, 2015 Author Share Posted November 15, 2015 (edited) 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 November 15, 2015 by shaddf Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 15, 2015 Share Posted November 15, 2015 I have no idea what your response is saying. Punctuation and caps might help as well as a re-wording. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 15, 2015 Share Posted November 15, 2015 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.