473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with image retrieval

15
ok so let's get the intros out here... I'm Nathan, a senior in high school. I attend a technology school, and in order to graduate, we have to complete a senior project. so we chose the following:

B.U.S.T.E.D. I have no clue what it stands for anymore, something stupid i'm sure. but the basic premise is thus: a student gets on a bus, scans their student ID, and they are listed as "riding" bus number... whatever the bus number is. That part works fine. But there is also an option to view student information. All student info is stored in a MySQL student_info table under the Busted database. What I need help with is being able to upload the student's picture, and have it pop up when the rest of their information is viewed, just like in the corner or something. everything else works, but i have no clue where to even start with this image thing. Please help!!! this is definately due February 7th.
Jan 18 '08 #1
11 1779
Atli
5,058 Expert 4TB
Hey Hejman. Welcome to TSDN!

Two options spring to mind when facing such a problem.

First, the old fashion way.
For that, you basically upload the image onto the file system of you server and add it's location to a field in your database. Then, when you want it displayed, you simply add the location to a <img> tag or something similar.

Second, the slightly more modern way.
This requires you to upload the image directly into you MySQL database as a BLOB object. This is more complex than the old fashion way, and some would reason this adds overhead as well (tho I've never really tested that) but, it can prove useful when the file system is somewhat inaccessible.
Check out this thread for more info on this.
Jan 18 '08 #2
Hejman
15
Hey Hejman. Welcome to TSDN!

Two options spring to mind when facing such a problem.

First, the old fashion way.
For that, you basically upload the image onto the file system of you server and add it's location to a field in your database. Then, when you want it displayed, you simply add the location to a <img> tag or something similar.

Second, the slightly more modern way.
This requires you to upload the image directly into you MySQL database as a BLOB object. This is more complex than the old fashion way, and some would reason this adds overhead as well (tho I've never really tested that) but, it can prove useful when the file system is somewhat inaccessible.
Check out this thread for more info on this.
Thank You for your time... I should be able to handle the "old fashioned way" you mentioned... i can't believe I didn't think of that... however is there a php way to upload to that filesystem?
Jan 18 '08 #3
Atli
5,058 Expert 4TB
Uploading files is actually extremely simple once you get used to it.

Check out this page at php.net
The examples there should shed some light on this.

When doing something like this it can be very helpful to check out the output of the $_FILES array to see exactly what it is you have to work with:
Expand|Select|Wrap|Line Numbers
  1. print_r($_FILES);
  2.  
Let us know if you run into any problems.
Jan 18 '08 #4
Hejman
15
Uploading files is actually extremely simple once you get used to it.

Check out this page at php.net
The examples there should shed some light on this.

When doing something like this it can be very helpful to check out the output of the $_FILES array to see exactly what it is you have to work with:
Expand|Select|Wrap|Line Numbers
  1. print_r($_FILES);
  2.  
Let us know if you run into any problems.

not sure if this relates to anything you just said, but i tried the earlier mentioned MySQL method, and it parse errors right about here: maybe you can tell me what i did wrong?

Expand|Select|Wrap|Line Numbers
  1. <...code omitted...>
  2. <h3><font color="#0000FF"><? echo "header('Content-type: image/jpeg');?>
  3. <? $rs = mysql_fetch_array(mysql_query("SELECT image from images where s_name = '".$s_name."')); ?>
  4. <? echo base64_decode($rs["image"])"; ?></font></h3>
  5. <...code omitted...>
  6.  
this is the error I get. line 49 starts with <? $rs =
Expand|Select|Wrap|Line Numbers
  1. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\do_lookup_bc.php on line 49
  2.  
Jan 18 '08 #5
Atli
5,058 Expert 4TB
The problem is actually in the line above the one you mention.
This is where the problem is:
Expand|Select|Wrap|Line Numbers
  1. <? echo "header('Content-type: image/jpeg');?>
  2.  
It should be either of these two, depending on what you were trying to do:
Expand|Select|Wrap|Line Numbers
  1. # This one will set the content type of the response
  2. #  to "image/jpeg", which would either cause the
  3. #  browser to render the page incorrectly or
  4. #  cause it to render the page as an image, which
  5. #  would be very weird considering all the HTML
  6. #  you have already added.
  7. <?php header('Content-type: image/jpeg');?>
  8.  
  9. # This would echo the header() function into the HTML
  10. #  as plain text, not executing it.
  11. #  I doubt that is what you wanted.
  12. <?php echo "header('Content-type: image/jpeg')";?>
  13.  
  14. # P.S.
  15. # Note that I changed the <? ... ?> tags you used
  16. # into <?php ... ?> which I recommend for 
  17. # compatibility's sake. It's good practice to always
  18. # use the full PHP tags like I did there.
  19.  
In any case, I think you are trying to use the wrong method here.

As far as I can see, you are trying to echo an image into the HTML document, setting the content-type and printing the binary data retrieved from the database.

You would in fact print the binary data as plain text into the HTML source, which is not exactly pretty :)

If you want to retrieve the binary data as an image, that must be done on a different document. You must set the content type using the header function and print ONLY the image binary data.
Jan 18 '08 #6
Hejman
15
ya this is really getting confusing- i'm in way over my head here. so i tried using the filesystem method, and reading the php.net help file thing that someone linked to, and all i found that i have a slight clue how to use was the HTML form to upload the file. so if the action is 'do_upload.php' what should i put in that php file so it will actually store the image in C:\xampp\htdocs\imaging, using the student's name as a filename? or better yet is that even possible?
Jan 23 '08 #7
Markus
6,050 Expert 4TB
google is your friend ;)

Here's a greta tutorial for uploading the image!

And to add to that, you can simply change the name of the image by using something like this:
[php]
//... code snipped

$_user = "username"; // fetch the username?
$_path = "uploads/".$_user; //join the to.
move_uploaded_file($_FILES["file"]["tmp_name"],
$_path); //save uploaded file with specific name.
echo "Stored in: $_path";


//... code snipped
[/php]
Jan 23 '08 #8
Atli
5,058 Expert 4TB
Yea, Markus' code is pretty much all you need.

The move_uploaded_file function does pretty much all that needs to be done.
All you have to is figure out the path you want the file saved in.

This may help:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # If something goes wrong with the upload
  3. # the $_FILES[x]['error'] element will contain
  4. # an error code that can tell you what went wrong.
  5. # If everything goes right, it will be set to 0.
  6.  
  7. # So, to make sure the upload was successful
  8. if($_FILES['MyFile']['error'] != 0) {
  9.  die("File upload failed");
  10. }
  11.  
  12. # The $_FILES[x]['name'] element contains the original
  13. # name of your uploaded file, so it can be used to
  14. # create the new path.
  15. $newPath = "uploads/". $_FILES['MyFile']['name'];
  16.  
  17. # The move_uploaded_files() function does the
  18. # actual moving for you and returns a boolean value
  19. # which indicates whether it was successful
  20.  
  21. # The $_FILES[x]['tmp_name'] element contains the temporary
  22. # path your server uploaded your file into. The move function needs
  23. # this value so it can move it to your new path.
  24. if(move_uploaded_file($_FILES['MyFile']['tmp_name'], $newPath)) 
  25. {
  26.   # Everything has been moved successfully
  27.   echo "Your file has been uploaded into '{$newPath}'";
  28. }
  29. else 
  30. {
  31.   # The move_uploaded_file function failed.
  32.   # If this happens you most likely do not
  33.   # have permission to write in the directory
  34.   # you are trying to move your file into.
  35.   echo "The file failed to be moved";
  36. }
  37. ?>
  38.  
Jan 24 '08 #9
Hejman
15
Yea, Markus' code is pretty much all you need.

The move_uploaded_file function does pretty much all that needs to be done.
All you have to is figure out the path you want the file saved in.

This may help:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # If something goes wrong with the upload
  3. # the $_FILES[x]['error'] element will contain
  4. # an error code that can tell you what went wrong.
  5. # If everything goes right, it will be set to 0.
  6.  
  7. # So, to make sure the upload was successful
  8. if($_FILES['MyFile']['error'] != 0) {
  9.  die("File upload failed");
  10. }
  11.  
  12. # The $_FILES[x]['name'] element contains the original
  13. # name of your uploaded file, so it can be used to
  14. # create the new path.
  15. $newPath = "uploads/". $_FILES['MyFile']['name'];
  16.  
  17. # The move_uploaded_files() function does the
  18. # actual moving for you and returns a boolean value
  19. # which indicates whether it was successful
  20.  
  21. # The $_FILES[x]['tmp_name'] element contains the temporary
  22. # path your server uploaded your file into. The move function needs
  23. # this value so it can move it to your new path.
  24. if(move_uploaded_file($_FILES['MyFile']['tmp_name'], $newPath)) 
  25. {
  26.   # Everything has been moved successfully
  27.   echo "Your file has been uploaded into '{$newPath}'";
  28. }
  29. else 
  30. {
  31.   # The move_uploaded_file function failed.
  32.   # If this happens you most likely do not
  33.   # have permission to write in the directory
  34.   # you are trying to move your file into.
  35.   echo "The file failed to be moved";
  36. }
  37. ?>
  38.  
thank you for helping me get this done... this looks to be exactly what i need to finish the server-side of things... and now for what i really suck at:
I need to host xampp on one PC, as like a dedicated server but still running XP, and network 2 other computers through it as dumb terminals and running through a switch. having subnetted the network, i am able to ping the 2 to the server and the server to the 2. But when i type in the network address of the server, if the page loads at all, it asks for a login but never goes anywhere, and no evidence of xampp, apache, or my project are anywhere to be found. Help?
Jan 28 '08 #10
Hejman
15
ok so thank you all for getting me the grade for this project, however we did make it to showcase for state so now i need help more than ever. I need to make the following happen, but have no slight clue where to start:

login as the bus driver
set a cookie so the bus driver's bus number is always retrievable (until the browser closes)

there's more but i would be happy with this for now... anybody get what i'm trying to do, or better is there an easier way to do it i'm overlooking?
Feb 15 '08 #11
Hejman
15
ok nevermind. we lost at regionals. but thank you all for your help... and i hopefully will keep developing this project... if i can get over the fact that i just wasted like 5 months of my life programming this stuff for nothing. i don't know.
Mar 4 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Matt | last post by:
In the following code, I have 2 questions regarding submit button with image. 1) Does this code <input type="image" name="populate" src="populate.gif"> behave the same as an HTML submit button...
4
by: Jake | last post by:
Does cookieless session state (with the sessionid embedded into the url) interfere with the browser's retrieval of cached images from one session to the next? Does the sessionid embedded into the...
7
by: BluDog | last post by:
Hi I am trying to store an image in an xml file, i vcan store it fine but the retreval is a bit of a problem: To String: Dim ms As New IO.MemoryStream Dim arrImage() As Byte...
2
by: addicted2rpg | last post by:
For background on this problem, see: http://support.microsoft.com/kb/q249232/ I essentially get a IHTMLWindow2 object, IHTMLDocument2 object, etc.. from an HWND of an internet explorer process. ...
0
by: frankkirchner | last post by:
There has to be a way to get an image into the XSLT transormation process so that it shows up on a Formatted Excel Spreadsheet. When saving an Excel spreadsheet to XML format - you lose the image...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
6
by: Daniel Fetchinson | last post by:
Hi all, There are a number of free tools for image matching but it's not very easy to decipher the actual algorithm from the code that includes db management, GUI, etc, etc. I have my own image...
21
by: DP | last post by:
Hi, I'm not sure if this is the right group to ask. I am developing a small image library and I don't know how to hide the actual path to the image. So I go to the stock photo library websites...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.