A simple image question ... could use some help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gijs
Forum Commoner
Posts: 53
Joined: Wed Aug 28, 2002 4:05 am
Location: Belgium

A simple image question ... could use some help

Post by gijs »

Hi,

I've been trying for about ten hours to get the sipmlest thing to work (trying different things, reading manuals and book), but somehow I'm not able to make it work.

What I want to do:
a) entering data into a table containing 3 fields:
logo_id | logo_name | logo_image
int (auto-increment) | varchar | varchar

Ok, I know you have 2 ways of storing images: blob and varchar.
Blob would be fantastic for me because the table would only contain 10 images of each 1 kb. I tried the thing with blob but didn't came anywhere nere. So I'll focussed on the varchar - variant.

I used the following form : (left out the excessive html-stuff)

Code: Select all

...

// Query all facility logos
$logo_SQL = "SELECT * FROM general_facility_logo WHERE logo_id='".$_GETї'logo_id']."'";
$logo_result = mysql_query($logo_SQL);
$logo = mysql_fetch_array($logo_result);


...

<table width="90%"  cellspacing="2" cellpadding="2" border="0">

<form method="POST" action="facility_logo_options.php">
<input type="hidden" name="action" value="update">
<input type="hidden" name="logo_id" value="<?php echo $logo&#1111;'logo_id'] ?>">

<tr>
<td bgcolor="#C0C0C0" width="100">Logo Name: </td>
<td bgcolor="#C0C0C0" width="100"><input type="text" name="logo_name" value="<?php echo $logo&#1111;'logo_name'] ?>" size="58" maxlength="100"></td>
</tr>
<tr>
    <td bgcolor="#C0C0C0" width="100">Logo Image: </td>
    <td bgcolor="#C0C0C0"><input type="file" name="logo_image" value="<?php echo $logo&#1111;'logo_image'] ?>">
	</td>
</tr>
<tr>
    <td bgcolor="#C0C0C0" colspan="2"><center><input type="submit" name="submit" value="OK"></center></td>
</tr>
</form>
</table>
In the php-file where variables are posted to I used following code

Code: Select all

// to check that action is actually set before trying to do anything with it
if (isset($_POST&#1111;'action'])) &#123;
switch ($_POST&#1111;'action']) &#123;

			case 'update':
			
			// Checking if the varaibles from form are set
			if (isset($_POST&#1111;'logo_id']) && isset($_POST&#1111;'logo_name']) && isset($_POST&#1111;'logo_image'])) &#123; 
			
			// Checking the image
			if($_POST&#1111;'logo_image'] !="none") &#123;
			// if there has been a new image to upload
			$source = $_POST&#1111;'logo_image'];
			$image_name = time() . $_POST&#1111;'logo_image'];
			// making the url
			$dest = "C:/www/TTOO/admin/general/facility_logo/" . $image_name;
			&#1111;b]$check1 = copy($source,$dest); &#1111;/b]			&#125;
			// Updating the record in the database
			$logo_update_SQL = "UPDATE general_facility_logo SET logo_name='".$_POST&#1111;'logo_name']."', logo_image='$image_name' WHERE logo_id='".$_POST&#1111;'logo_id']."'";
			
			// Displaying a message depending on the outcome of the query
			$bool = mysql_query($logo_update_SQL);
			if($bool == 1) echo "<SCRIPT LANGUAGE=Javascript>window.alert('The Facility Logo has been updated.')</script>";
			if($bool <> 1) echo "<SCRIPT LANGUAGE=Javascript>window.alert('There has been an error.')</script>";
			
			// Performing a a refresh of the facility logo list
			$logo_SQL = "SELECT * FROM general_facility_logo";
			$logo_result = mysql_query($logo_SQL);
			
			
			// Kicking out the variable
			unset($_POST&#1111;'action']);
			
			&#125; else &#123; 
   		  	// actions when $_POST&#1111;'action'] not set 
		  	echo "The variables for the form in facility_logo_edit.php are not set";
			&#125;
			// Stopping the switch statement
			break;
			
			default :
			echo "The Switch Case: Update has not been performed";
&#125;
&#125; else &#123; 
// actions when $_GET&#1111;'action'] or $_POST&#1111;'action'] are not set 
// none defined for the moment !!!!
&#125;
I get following error message in line 26 (= in bold in the previous code):

Code: Select all

Warning: Unable to create 'C:/www/TTOO/admin/general/facility_logo/1031865865C:\\Documents and Settings\\Administrator\\My Documents\\beelden TTOO\\solarium.gif': Invalid argument in C:\www\TTOO\admin\general\facility_logo_options.php on line 26
I dont' get any error message from the bool-thingy, so when I check each time I update a record there is an entry for the image logo (f.e. 1031842707C:\Documents and Settings\Administrator\My Documents\beelden TTOO\vegetarian.gif ==> this is the timestamp and the location I browsed the file from)


Questions:

1) Can anybody clearify me where I got wrong ?
2) Is there a tutorial or article or anything I can read more on uploading and displaying images with php and mysql ? If possible something comprehensive.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

it seems to be looking for

"C:/www/TTOO/admin/general/facility_logo/1031865865C:\\Documents and Settings\\Administrator\\My Documents\\beelden TTOO\\solarium.gif"
User avatar
gijs
Forum Commoner
Posts: 53
Joined: Wed Aug 28, 2002 4:05 am
Location: Belgium

Post by gijs »

Thanks hob_goblin for responding,

But I still don't see what you mean.
it seems to be looking for

"C:/www/TTOO/admin/general/facility_logo/1031865865C:\\Documents and Settings\\Administrator\\My Documents\\beelden TTOO\\solarium.gif"
As I understand the error message: "it's unable to create the file because of an invalid argument on line 26"

Therefore I don't understand "it seems to be looking for".

With the copy function it should have copied the:

1031865865C:\\Documents and Settings\\Administrator\\My Documents\\beelden TTOO\\solarium.gif"

to the $dest which is :
C:/www/TTOO/admin/general/facility_logo/

or do I see this wrong ?

Thanks in advance,

Gijs
User avatar
gijs
Forum Commoner
Posts: 53
Joined: Wed Aug 28, 2002 4:05 am
Location: Belgium

apparently file upload is tricky, so let's simplify

Post by gijs »

Hi,

I read some more on this topic and if I understand corectly I'm trying to perform a file upload and then adding the uploaded file to a tabel.

This is apparently very tricky. I found a ready to use file upload class at: http://dave.imarc.net/
Only bummer: *nix only. Works nice though.

Back to my problem:

I can display stored images on as follows:

Code: Select all

<img src="<?php echo $rootdir ?>facility_logo/pets.gif">
If I would store the name "pets.gif" in the tabelfield 'logo_image'
How would I have to display it ? :oops: I tried several variants on this:

Code: Select all

<td bgcolor="#C0C0C0" width="200"><?php echo "<img scr='$rootdir . facility_logo/" . $logo&#1111;'logo_image'] . "'>" ?></td>
But it doesn't seem to work. :?

Some help would be appreciated enormously !

Thanks in advance,

Gijs
Post Reply