Click to See Complete Forum and Search --> : NEWBIE: Help with embedding in PHP


syar
03-02-2008, 02:31 PM
OK, I am new to PHP coding and i am currently working on my first site using it. I need to have an photo uploading system on the site so users can upload there photos. I have found an awesome tutorial on how to setup the upload system and also to generate a page with the photo's on which i then include within the photo gallery page. Anyway although the tutorial was fantastic in showing me how to setup the upload system it didn't mention how to customize the generate.php script (show below). I REALLY need help in making the PHP script embed a CSS style to the tag so everything can be automated. All i really need the CSS script to do is put a border around the picture and for it to be resized.

Also if possible i would like it to generate the link for the JS lightbox feature but that is not as important. As long as the user can see a thumbnail (with CSS) of their picture and there is a link to a full resolution version that is all that matters

<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$pfile = fopen("userphotos.htm","a+");

// If everything is OK -> store user data

fwrite($pfile, "\r\n<embed src = \"$target_path\" />\r\n<p>");
fclose($pfile);

?>


Please can someone help me out as this is the forth forum i have been on looking for answers to this and no one seems to be helping me out

tfk11
03-03-2008, 06:56 PM
The lack of help is probably due your lack of understanding html basics. In order to write a script that generates html you'll need to know what it is your trying to generate first. The info you need can be easily found in countless html guides and references. Google "html css guide".

syar
03-04-2008, 02:28 PM
I know CSS and HTML and am perfectly capable in writing them. The problem seems to come when trying to put them into the code. I am not sure about how i should add them. Its the PHP part i am unsure about. Here is what i am trying to add in.


<a href="$target_path\" rel="lightbox" /><img class="img" src="$target_path\" />


However i seem to write the code i seem to get an error

syar
03-04-2008, 03:35 PM
I do know HTML and CSS. Its just that for some reason i can't work out how to get the script to embedded them into the tag. I have put down what i am looking to want to do. I hope that someone can just tell me where i am going wrong and show me how it should look.

Note: I know the CSS script is wrong but this is just an example. I am going to update the CSS after i find an answer.

<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$pfile = fopen("userphotos.htm","a+");

// If everything is OK -> store user data

fwrite($pfile, "\n<embed src = \"$target_path\" href = \"$target_path\" rel="lightbox" class = \"border: 3px #d5d2d2 solid; height:100px; width:150px; text-align:left;" />\n<p>
fclose($pfile);

?>

Altriak
03-04-2008, 07:35 PM
Hi :)

I may be wrong but it looks like you have a #, which is the symbol for php comments. It's probably cutting off the rest of the code. And I don't think you can have a "href" in an embed? And what's that trailing <p> for?

If that doesn't help...maybe posting the error would be good.

syar
03-05-2008, 03:28 AM
Hi,

I don't think the '#' is cutting off anything, I have tried it with and without to the same effect. The 'href' is no problem now and works fine. I don't know what the <p> is there for, it is something that the original developer put there and i forgot to take it off when i pasted the code here, I have took it off in my code though.

I was playing about with the code last night and have made alot of changes. I am starting to understand it all more now and i have gotten to the point where it is all working but i still seem to have a problem getting a border round the photo. The photo will get resized so i know that is working and it will give me a link to the original photo for a full screen view, but no border.

Here is the code i have now;

fwrite($pfile, "\r\n<a href = \"$target_path\" ><img src = \"$target_path\" img class = \"border:thick #2D83A7 solid; height: 100px; padding: 10px;\" /></a>");
fclose($pfile);

and here is the output in which it generates

<a href = "uploads/photo.jpg" ><img src = "uploads/photo.jpg" img class = "border: thick #2D83A7 solid; height: 100px; padding: 10px;" /></a>

Can't work out exactly what it might be that is causing the css to only resize the photo and not put a border round it. Unless it has something to do with the padding

MrCoder
03-05-2008, 06:13 AM
<img src = "uploads/photo.jpg" style = "border: thick #2D83A7 solid; height: 100px; padding: 10px;" />

syar
03-05-2008, 12:44 PM
OMG i feel so stupid. I know i am a newbie but i should of know that. I guess that is what you get for coding when you are to tired to know what you are typing lol. Thanks anyway for your help. Everything works perfect now :D