|
pholusho (m)
|
hello yah all, am having this little problem, i created this page which as a file field component i intend to use it for uploading pictures to my database, but when i tried it i did not submit to the database at all but i have been able to submit text to the database.please bear in mind that i make use of php my admin and macromedia dreamweaver(dont know php codes that much, but can use echo lol  ). Please kindly help me out thank you.
|
|
|
|
|
|
smartsoft (m)
|
there is a whole lot, when talking about dumping images to your database, you must create a temp file on your server and emmmmmmmmmmmmmmm hang brb,
|
|
|
|
|
|
pholusho (m)
|
still no solutions yet,
|
|
|
|
|
|
pholusho (m)
|
please dont tell me nobody as a clue about this
|
|
|
|
|
|
yawa-ti-de (f)
|
I would have a clue if you didn't use a DW component so sorry, but I can't help you on this.
Possible issue: The type of data type specified for the image column (I blv it shd be BLOB)
|
|
|
|
|
|
pholusho (m)
|
Thanks yawatide, you mean i should specify my data type on to be blob, believe me i have done that but dreamweaver would not just submit it to the database, what do i do now,
|
|
|
|
|
|
yawa-ti-de (f)
|
I am sorry but like I said, I don't use DW. As a matter of fact, I loathe it with a passion. Hopefully some DW users in here will help you out.
|
|
|
|
|
|
uspry1 (f)
|
I hope you do know how to set up MySQL connection using Dreamweaver 8 like this link tutorial below: http://www.nebulex.com/index.php?option=com_content&view=article&id=6&Itemid=62Then you create your own dynamic form using Dreamweaver recordset to upload pictures into MySQL database for STORING or RETRIEVING purpose. You will need Dreamweaver extension (component) called PHP Upload from Adobe.com or below link from DMXzone.com: http://www.dmxzone.com/showDetail.asp?TypeId=25&NewsId=6346Basically you should know how to use PHP, MySQL and Dreamweaver recordset to make Picture upload work. There are few Dreamweaver database with upload picture tutorials found on books as well as Adobe.com. Good luck!
|
|
|
|
|
|
kehers (m)
|
To start wit, it is not advisable to store up images in your db fields. Store it in a folder snd store the imae path in the db instead. Attached is a snippet for that <?php if(move_uploaded_file($_FILES['source']['tmp_name'], "foldername/".$_FILES['source']['name'])){ //query $r = mysql_query("insert into tableName (src, size) values ('".$_FILES['source']['name']."', '".round($_FILES['source']['size']/1024."')"); if($r){ //upload success } else{ //sql query error //echo mysql_error(); } } else{ //Upload error } ?>
And if you must store it in a db, simply make the data type f the field blob (binary large object - if Im correct) as Yawa said and once u upload, use any of the php file functions to read the content (binary) and it is that u insert into the db. Here is a simpel analogy: <?php $filecontent = file_get_contents('path/to/uploaded/file.ext'); $sql = "insert into tbl (px) values ('$filecontent')"; //, the query and otherthings follows ?>
|
|
|
|
|
|
pholusho (m)
|
uspry1 thanks for your advice, but you see i know how to connect to the database, insert records to my database, but i tried usin the file field but it is not just working i tried connecting it the same way you connect a text input field and also made sure i specified blob for data type when i tested it on my browser it did not submit an error message comes up like field cannot be null. i will also check on the links you dropped and i'll come and give you a feed back chao. @all thanks for your opinions too.
|
|
|
|
|
|
pholusho (m)
|
yeah i tried the same process again now its submitting to the database showing [blob-null] but i cant see the pix it self so i tried creating a new page with a dynamic table which display the recordset from my database field picture but when i tried running it the picture didnt show. please what should i do.
|
|
|
|
|
|
kehers (m)
|
The null means no data is inserted in the field. Are u sure the image is uploaded in the first place? <form action="" enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524280"> Picture source: <input type="file" name="source" /> <input type="submit" value="Upload" /> </form>
The MAX_FILE_SIZE parameter is important and should come before your input file. its value is the maximum bytes allowed (here it is set to around 5MB). Take note of the form enctype as well. For uploads, it should be set to multipart/form-data
|
|
|
|
|
|
kehers (m)
|
LAst post's edit. The MAX size specified there is 500KB and not MB. That said, the next thing is handling the uploaded image. First, create a folder called tmp and then handle the submission this way $err = array( 0=>"There is no error, the file uploaded with success", 1=>"The uploaded file exceeds the maximum upload filesize", 2=>"The uploaded file exceeds the maximum upload filesize", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); if(move_uploaded_file($_FILES['source']['tmp_name'], "tmp/".$_FILES['source']['name'])){ $filecontent = file_get_contents("tmp/".$_FILES['source']['name']); //query $r = mysql_query("insert into tbl (src) values ('".mysql_escape_string($filecontent)."')"); echo mysql_error(); } else{ echo 'Upload Error: '.$err[$_FILES['source']['error']]; }
|
|
|
|
|
|
kehers (m)
|
Im hoping you have average skills in PHP and Mysql so Ive purposely left out some more detailed parts. And by the way, the create sql for the tbl table Im using here goes like this CREATE TABLE `tbl` ( `id` int(11) NOT NULL auto_increment, `src` blob NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM
So lets continue. With the form and upload probably taken care of. The last worry is displaying the image. You actually need a script that will take of the image display. Lets call it image.php. Here is what it will contain: <?php mysql_connect("localhost", "db_usrname", "db_password"); mysql_select_db("ur_dbname"); // $id = $_GET['id']; $r = mysql_query("select src from tbl where id='$id'"); list($src) = mysql_fetch_array($r); echo $src; ?>
So that from anywhere, u can simply call up any image stored in the tbl this way: <img src="image.php?id=1" alt="Hmmm, " />
And thats all. The id of the needed image is simply passed to image.php where it is retrieved and the value of the blob field is outputted. By the way, there may be better ways to achieve storing images in a database but this is the idea I have. Anyone with other ideas should please share. Let me know if it works.
|
|
|
|
|
|
pholusho (m)
|
kehers you are really appreciated but you see i dont know codes that much so most of those things looks like magic to me is there know way that i could do this with dreamweaver without using codes?
|
|
|
|
|
|
kehers (m)
|
Sorry to burst your bubbles but i dont do DW as well. We can only hope another developer in d house will help out on d DW part.
|
|
|
|
|
|
pholusho (m)
|
@kehers what software do you use?
|
|
|
|
|
|
kehers (m)
|
I code directly in Editplus (an editor like d notepad, notepad++, and co)
|
|
|
|
|
|
pholusho (m)
|
i have gotten my hands on a book on php and mysql i hope it helps, thank yall for you advice and support
|
|
|
|
|
|
uspry1 (f)
|
@pholusho
You are more than welcome and wish you the best luck to work on php and MySQL using Dreamweaver 8.
|
|
|
|
|
|
yankitwizy (m)
|
I do use dreamweaver and phpmyadmin as well and it is true that with dreamweaver you could do a lot of PHP stuff without writing one single code but the truth is to do this particular thing you want, you must write code. There are no two ways about it. If you don't write then you can't get this done.
|
|
|
|
|
|
pholusho (m)
|
thanks at all. now am onto coding it my self but note pad is just messing up, meaning when i write my php codes with note pad the browser don't display the desired ouput, but when i used the same codes in the code section of dreamweaver they work well what could be wrong?
|
|
|
|
|
|
yawa-ti-de (f)
|
How are you saving your files?
In notepad, if you don't select "all files" from the "save" or "save as" dropdown, your file will be saved like so, "flename.php.txt" so it is important that you select "all files" under the "file type" menu to preserve the .php extension. If you don't want to go that route, then enclose your file name in double quotes when you name it.
Hopefully, this solves your problem using notepad.
|
|
|
|
|
|
webdezzi (m)
|
Kehers and yankitwizy has answered it all
Dreamweaver will not help you, you have to code it urself Talking about notepad, for a newbie like you, i will advise you still use the code view of dreamweaver, set the enctype of the form to multipart/form-data use kehers codes and you should be fine
However, i dont like storing my image in databases for some special reasons, but if thats what you want you will have to set the database column type to BLOB and note that blob does not require a character length
Kehers has posted all these already, so he might be able to help if you stil have problem
|
|
|
|
|
|
*dhtml
|
The interesting thing i find here is that, i was not the only person that hate DW, i have written a number of scripts, classes in javascript, php, and i have a whole lot of very useful libraries, and i achieved this without DW, and NotePad++ is my favorite editor. Now i am tryin to go all ajax like my new subsite http://www.ds.mwebng.net uses alot of ajax stuffs, but if u are a DW person, u cant benefit from alot of stuffs, u must wait for DW to get there. It is not just me, many professionals find it tough to do sophisticated coding in DW, it is more difficult that to handcode directly using classes and all that. So it is either u are fully into DW or NOT! and i prefer NOT! There are lots of free php uploader scripts online, just type it into google, integratin it into DW especially for a beginner can be quite tough!! I guess that is why most people kept quiet, even i cannot post any code here to help you, and yet had u asked for how to upload images without reloading the page, i will post back codes to u, but again, they will not work easily with DW!
|
|
|
|
|
|
webdezzi (m)
|
me i love dreamweaver ooo
|
|
|
|
|
|
*dhtml
|
And what is the hashbang #!/usr/bin/girl on your profile meant to do? open a door for girls or what? Anyway, no problemo, carry go, i can use DW too but to a limited extent.
|
|
|
|
|
|
*dhtml
|
And what is the hashbang #!/usr/bin/girl on your profile meant to do? open a door for girls or what? it is obviously not perl unless maybe the cgi-bin directory has been changed to bin-girl or something. Anyway, no problemo, carry go, i can use DW too but to a limited extent. Anyway, my script library is quite large and i can code quite fast. We could do a competition some day, DW vs NP++ [but i will have access to my personal script library sha] - and we will see who will win - 1st prize - ehm? one enterprise project [i mean a big project for a client - of course from the looser]!!
|
|
|
|
|
|
webdezzi (m)
|
thats a perl path for use girls and dump them (Please don't ask me if i do it)
About DW, I see loads of advantages it has over many web authoring softwares out there
1. Has code coloring like others 2. with the assets panel, i can preview my images without having to drag them in to see which image is which, a time saver 3. Snippets panel allows me to save frequently used codes, so i just double click to have it in my script 3. I find the inbuilt FTP very useful in special situations, though i rely mostly on CuteFTP 4. Using DW's tools for generating code help build SECURE websites, This is best for beginners as they transition into being a pro, They have nothing to fear 5. the dreamweaver exchange allows you to install some ajax extensions so you can build ajax sites right from dreamweaver 6. The design view allow preview, so you don't have to switch to the web browser at an initial stage of development 7. The code view gives you the flexibility of remaining a hardcore programmer that you want to be
So why shouldn't i love this baby
|
|
|
|
|
|
*dhtml
|
You are very correct about all that - DW is excellent - though some of us that all we do is coding and loads of it - though some times i do have to rely on it. I still even use FRONTPAGE atimes to do image mapping - but now, i prefer to my mapping direct from macromedia fireworks - anyways i will like you guys to contribute to the thread i just started - it is on http://nl.mwebng.net/ - that is a redirection path to the thread here on nairaland - talking about dynamic website design featuring javascript, dom, ajax, css,
|
|
|
|
|
|