View Full Version : Post, Read, and Upload
cgibie
12-28-2005, 06:56 PM
Hey guys, I really have no idea about this... I tried to think about it logically but still I could not find solution to it.
Here is the problem... Ex: I have a post.cgi and a readpost.cgi, which means whatever I typed in the input box in post.cgi will be read by readpost.cgi... I achieved the goal, but the thing is.. I added an upload.cgi file which allows me to upload pictures.... my question is ... I want to post and upload at the same time, the post file (txt) go into one directory and the uploaded image goes to another directory...
Well, in readpost.cgi, how can I read the text file and see the image after submitting the post.cgi? For example,
December 25, 2005
Title: Test1
Content: Hey
December 24, 2005
Title: Test2
Content: Hello
I want to achieve is that:
December 25, 2005
Title: Test1
Content: Hey
(The image is under this content)
December 24, 2005
Title: Test2
Content: Hello
(The image is under this content)
mlseim
12-28-2005, 07:47 PM
You're somehow going to have to associate your text with a certain image.
So, you'll need to create a flat-file database to save each entry in a list.
If there's an image associated with it, that image filename will be on the
same line as the text. When you read the flat-file database, each line
at a time, if there's an image associated with it, it will display the image
after the text. If no image, then it just goes to the next one in the list.
It can be a pretty simple database like this:
December 25, 2005|Test1|Hey||
December 24, 2005|Test2|Hello||
December 25, 2005|Test1|Hey|mycar123.jpg|
Lines without images will not have a .jpg in that spot.
You'll have to learn about writing lines to a file and reading
lines ... using the "split" command to separate pipes "|".
That will be a good learning exercise for you.
cgibie
12-28-2005, 09:25 PM
I could read and write to text files, but I don't know how to write the image (mycar123.jpg) to that text file also.... and I have 2 seperate cgi's files (write and upload.cgi), shall I combin them into one or just simply use "require" function?
I tried to write the inputs to my textfile, it gave me like this:
Date = Wed Dec 28 16:27:52 2005
Title = Test
Content = Test1
file1 = C:\Documents and Settings\Owner\My Documents\My Pictures\CutePics\a1.jpg
It's weird, isn't it?
mlseim
12-28-2005, 10:51 PM
You still put the image in your image folder like you do already.
In the flat-file database, you just have the name of the image file stored,
not the image itself. When you read the lines in the database, that filename
will be a variable that you'll use when you display the text.
Sort of like ...
when you read the lines and split them into variables,
the image name will become $field4 (as an example).
.
.
$field4 = "mycar123.jpg";
.
.
. further down in your script you display the image ...
print "<img src='../myphotos/$field4'> \n";
============================================
If this is homework, be honest and let us know.
We're glad to help, but we don't do homework (just give hints).
If you're making a CMS (content management system) for a website,
you might be better off finding a free script that is already written.
It could be Perl or PHP. No use re-inventing the wheel. Unless of course,
you're teaching yourself Perl ... then, more power to you:thumbsup:
EDIT:
About the path when uploading ... yes, it reads the whole path that
was taken from the "browse" part of your form. You need to parse
out the filename only and not the path in front. I don't have the
script in my head off-hand to do that ... I'll look for it. FishMonger
usually knows that "regex" stuff like the back of his hand.
cgibie
12-28-2005, 11:16 PM
This is NOT homework... I'm teaching myself and trying to create a blog for myself. I know there are many free scripts out there, but after I downloaded and take a look at them, I rolled my eyes without any understandings. That's why I'm trying to code up everything on my own, and of course without you guys' help, I will be so miserable.. this is pain in the butt... I'll come back later. I've been working on this read and upload for 5 hrs now... it's time to relax :)
mlseim
12-29-2005, 01:50 AM
Good for you ...
Perl is a really cool language to learn.
Here's a suggestion that will really help you out.
1) Give us a link to your blog, even though it doesn't work.
we can then see your form, etc.
2) Have one webpage dedicated to a .txt listing of your Perl script.
Keep it updated with the latest version you have running and give us a
link to that too. So we can view what Perl script you're executing,
and you won't have to keep listing on this forum ... we'll just view
your .txt file.
When you write your data to a file, also write your data to another
.txt file in your main directory ... so we can also see that (and give us
the link to that too).
Use Google to search out tutorials and examples like:
http://www.google.com/search?q=perl+split+example&btnG=Search
If you're stuck, use Google first.
Ask away on this forum and we can view your Perl script to see where
you might be having problems, and offer hints.
Don't get frustrated ... just have fun. You'll be amazed at how fast
you pick this up.
cgibie
12-29-2005, 02:40 AM
Hey thanks for the encouragement, after another 3 hours, hehe... I finally got that read and upload things done. Yahoo! I'm so proud of myself now, haha... but they Great thanks to you, man... cause you gave me the idea of flat-file database thing. :thumbsup:
I'll come back when I got stuck on other section :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.