insert/read html file from blob field - sql

How can I INSERT and RETRIEVE with SQL language, an HTML document from a BLOB field into db2 on ibmI ??
I put the testing.html inside fylesystem but I don't know if this way is correct or if I can also use a file into my local PC.
I tried this code from STRSQL without success:
INSERT INTO LIB/FILE VALUES('','C','000001',BLOBFROMFILE(/PATH/testing.html))
Is it possible to enter an HTML document type or is there another type field to manage it?
After this procedure I need also a SQL string than can read it.
Thanks!

$data = file_get_contents("/PATH/testing.html");
$data = mysql_real_escape_string($data);
$query = "INSERT INTO FILE VALUES('','C','000001','$data')";
mysql_query($query);
edit:
linux file system
lets assume you are working on /var/www/username/public_html/ folder
when u try /PATH/testing.html
program looking for /PATH/testing.html
direct access to root folder probably u dont have that right
in the other hand when you try PATH/testing.html ( no / at start )
program look for /var/www/username/public_html/PATH/testing.html

Related

Reading Images, Pdf from SQL Database via LINQPad

I have a table in a database that contains all kind of attachments, images, pdf, excel, and other formats. creating an application is not an option, so I googled other options and I found this related question that mentioned LINQPad I downloaded it but I still do not know how exactly it works. Anyone please explain that to me? I can query the attachments using sql query but not sure how to dump them and preview them via the mentioned tools.
Following on from Dan's answer, once you have the data context set up you can dump the images from the database. I use this snippet for checking an image I've written to the database, you should be able to edit as required to match your scenario:-
var ii = ItemImages.Where (v => v.Id == 10).FirstOrDefault();
using (var ms = new MemoryStream(ii.Image.ToArray()))
{
System.Drawing.Image.FromStream(ms).Dump();
}
Use the Util.Image built in utility for images.
Ex:
var personPictures = PictureTable.Take(1);
Util.Image(personPictures.First().Picture).Dump();
Util.Image takes a byte array.
Depending on your database of your choice, most likely you'll need a data context driver
http://www.linqpad.net/richclient/datacontextdrivers.aspx
Once you establish a connection you can start writing queries against the data

How to creat and read databse in actionscript3 ( ini or sql )?

I need a way to create a swf application that creates a file in the same folder that my swf will be and to be able to read and write stuff on it so i can have a "save" file.
I wanna know if that's possible and the easiest way for me to do it.
Thanks
About the database, you have a similar question here and also a positive answer, hope will help you.
To save your file you will need to use the File API
var file:File = File.desktopDirectory.resolvePath("myFileName.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("This is my text file.");
stream.close();

Change database of a ColdFusion website

I'm newbie in ColdFusion.
I have a running ColdFusion website I'd like to update. I've copy the database to make some test, in the ColdFusion manager I have created a new datasource with the copied database. But now how can I tell my website that it need to use the copied database?
Thanks
Look in your code and find any cfquery tags and make sure they are using the new dsn in the datasource attribute. Depending on how the code is written, there may be a global variable that holds the dsn and you can just change it there.
Now that you have a test database, you probably want to use conditional logic to determine which one to use. Here is an example from one of my files.
<cfscript>
if (cgi.path_info contains "dwtest") {
dsn = "AntibioticsTest";
} else {
dsn = "Antibiotics";
}
</cfscript>
<cfquery name="GetLastInsertDates" datasource="#dsn#">
sql not relevent
</cfquery>
As mentioned in jhinkley's answer, this variable might be a global variable in which case it's most likely found in Application.cfc.

Get id of file upload control

I am trying to find the name of ID of the input item that coresponds to the
file that is being uploaded...
<input type="file" id="FUtxtval1" name="FUtxtval1"/>
iterating over input items to find the first file input field:
function FindFirstFileFieldId()
{
var inputFields = document.getElementsByTagName("input")
for(var i=0;i<inputFields.length;i++)
{
if(inputFields[i].type=="file")
return inputFields[i].id;
}
}
The ID of the element is simply "FUtxtval1" (whatever is in the ID tag)
--
For JavaScript you can access this by using
var element = document.getElementById('FUtxtval1');
So you could then do something like
document.element.disabled=true;
--
For jQuery (Also JavaScript) you would use
$('#FUtxtval1').whatever
--
For PHP you would use
$_POST['FUtxtval1']
Assuming this is part of a form
For PHP if you actually want the file you use the handle
$_FILES['FUtxtval1']['whateverwanted'];
See http://www.tizag.com/phpT/fileupload.php
If the problem is that there may be many input tags on the form, and you're interested in discovering which one is specifically used for uploading files, this bit of jQuery code would accomplish that:
var id = $('input[type=file]').attr('id');
If the problem is that you know the element's ID but do not know the name of the field, you can use:
var name = $('#FUtxtval1').attr('name');
If you're hoping to find out the filename of the file your visitor has chosen in that field through JavaScript, you're stuck. JavaScript does not get any access to that information. You'll have to submit the form and let a server-side script determine the filename at that time.
If I understand correctly, you are trying to obtain the id of the uploaded file using javascript? If so, you will have to process the uploaded file using php ($_FILES['FUtxtval1']) and then print the id to a javascript variable.
Is that what you wanted?
If not, update your q to provide a bit more info about what you are trying to achieve.

Create files using list of filenames and add content to each

I need to make a bunch of redirect pages as I've recently updated my web site which previously used .html files and now all the files are .aspx. I have a tab-delimited file containing a list of original filenames and the corresponding new filename.
It seems like there should be a language out there that I should be able to create a file using the first column for the filename and insert the second column as its content with some additional text for the 301 redirect.
Could someone point me in the right direction as to what language(s) would be able to accomplish this? Also, if you could also point out the name of the method/function I would be using so I know where to begin when creating the file.
I've needed to do this type of thing many times and am willing to learn a new language (Perl, Python, or whatever) to accomplish this, but I just need pointed in the right direction. I am using Windows XP to develop on.
Thank you for your time.
This can be done in a few lines of C# if you already are working with aspx you can process this in the codebehind on a dummy page.
System.IO.StreamReader myreader = new System.IO.StreamReader(Server.MapPath("~/Text.txt"));
while (!myreader.EndOfStream)
{
//9 is Ascii value of Tab bad idea to split if the second set of values might contain tabs but can reconstruct the data if inputString.length >2
string[] inputString = myreader.ReadLine().Split(char.ConvertFromUtf32(9).ToCharArray());
//construct the path to where you want to save the file, or if the filename is the full path all the better
System.IO.StreamWriter filemaker = new System.IO.StreamWriter(#"C:\" + inputString[0]);
filemaker.Write(inputString[1]);
filemaker.Close();
}