CraigGT Posted May 31, 2007 Share Posted May 31, 2007 Hello all, I am trying to make a simple blog type tool for my page so I can log into it and upload an image and short paragraph of text to a file. I'm unsure weather or not I need to use mysql for this. Any help or links to useful tutorials are greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/ Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 MySQL would make it easier, faster and more reliable, but not necessary. www.google.com great link, search for php mysql tutorial Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265806 Share on other sites More sharing options...
redarrow Posted May 31, 2007 Share Posted May 31, 2007 http://www.w3schools.com/ this site will help with all your needs. Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265808 Share on other sites More sharing options...
redarrow Posted May 31, 2007 Share Posted May 31, 2007 frost i dont no if your right as i thort a text file database was a lot quicker . Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265809 Share on other sites More sharing options...
CraigGT Posted May 31, 2007 Author Share Posted May 31, 2007 Thats what i wanted to do , make a small text database that I would include. What Im having a problem with is , How do I connect the forms I created to the php. Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265818 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 Create a test and see. db structure: create table test ( id int(2) NOT NULL auto_increment, blog text NOT NULL default '', PRIMARY KEY (id) ); INSERT INTO test (id, blog) VALUES (1, 'This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text '); INSERT INTO test (id, blog) VALUES (2, 'This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text '); INSERT INTO test (id, blog) VALUES (3, 'This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text '); //blog.txt 1::This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text 2::This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text 3::This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text This is a blog text <?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $id = 2; $time_start = microtime_float(); mysql_connect('localhost', 'yourusername', 'yourpassword') OR DIE('no connection can be made'); mysql_select_db('yourdbname') OR DIE('no ddb could be selected.'); $query = mysql_query("SELECT id, blog FROM test WHERE id = " . $id . " LIMIT 1"); $row = mysql_fetch_assoc($query); echo 'The blog with the MySQL id ' . $row['id'] . ' and text . ' $row['text'] . '<br /><br />'; $time_end = microtime_float(); echo 'Took ' $time_end - $time_start . ' seconds to complete!'; $time_start = microtime_float(); $file = file('blog.txt'); foreach ($file as $blogs) { list($bid, $blog) = split('::', $blogs); if ($bid == $id) { echo '<br />The blog with the text id ' . $bid . ' and text . ' $blog . '<br /><br />'; break; } } $time_end = microtime_float(); echo 'Took ' $time_end - $time_start . ' seconds to complete!'; ?> Let me know which one is faster. Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265822 Share on other sites More sharing options...
corbin Posted May 31, 2007 Share Posted May 31, 2007 Frost that won't be accurate. Get a text file with 1000 of those entries, and then get a mysql table with 1000 entries. MySQL will beat flat files face in with that test. Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265828 Share on other sites More sharing options...
CraigGT Posted May 31, 2007 Author Share Posted May 31, 2007 I don't think mysql will be needed because the file doesn't need to be dynamicly awesome, I just want to upload a picture and a short description of the hardware I've used . Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265831 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 Frost that won't be accurate. Get a text file with 1000 of those entries, and then get a mysql table with 1000 entries. MySQL will beat flat files face in with that test. Yea, but even so, that one should be pretty accurate I would think. Either way if you want to be able to edit the entry etc, MySQL is the way to go. If not than stick with the flat file. Less of a hassle one way or the other. Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265860 Share on other sites More sharing options...
tjodolv Posted May 31, 2007 Share Posted May 31, 2007 If we are talking about a lot of images, a database would be more convenient, but for just a few images, or if you don't have access to a database, text files are ok. You could do it like this: <?php if (isset($_POST['upload'])) { if (empty($_FILES['picture']['name'])) { ?> <div> <p>No file selected. Try again.</p> </div> <?php } // end no image selected else { $temp_file = $_FILES['picture']['tmp_name']; $dest_file = $_FILES['picture']['name']; move_uploaded_file($temp_file, "images/$dest_file") or die("Error: Could not copy the uploaded image."); // image upload completed, moving on to the description $description_file = str_replace(".jpg", ".txt", $dest_file); // setting the name of the textfile to the same as the name of the image, only with .txt ending $new_description = fopen("images/$description_file", "w"); // the textfile is located right next to the image $descr_content = $_POST['description']; fwrite($new_description, $descr_content); // writing the description to the textfile fclose($new_description); // close the file ?> <h3>Image uploaded!</h3> <p><img src="images/<?php echo $dest_file; ?>" /><br /> <em>images/<?php echo $dest_file; ?></em></p> <p>The associated text is stored in <em>images/<?php echo $dest_file . "_description.txt"; ?></em></p> <p>The text:<br /><?php echo $_POST['description']; ?></p> <hr /> <?php } // end else } // end if isset($_POST['upload]) ?> <form action="" method="post" enctype="multipart/form-data"> <p><input type="file" name="picture" /></p> <p><textarea name="description" rows="4" cols="40">Description...</textarea></p> <p><input type="submit" name="upload" value="Submit" /></p> </form> And later on retrieve it like this: <?php if (isset($_POST['retrieve'])) { $image = $_POST['image']; $descr_tmp = str_replace(".jpg", ".txt", $image); $description = file_get_contents($descr_tmp); ?> <h3>The image:</h3> <p><img src="<?php echo $image; ?>"><br /><em><?php echo $image; ?></em></p> <h4>Description:</h4> <p><?php echo $description; ?></p> <hr /> <?php } // end if retrieve $folder = "images/"; $folder_ref = opendir($folder); ?> <h3>Select an image to retrieve</h3> <?php while ( $next = readdir($folder_ref) ) { $filename = "images/" . $next; if ( strstr($filename, ".jpg")) { // we are only listing .jpg files ?> <form action="" method="post"> <p><img height="200" width="200" src="<?php echo $filename; ?>" /><input type="hidden" name="image" value="<?php echo $filename; ?>" /><input type="submit" name="retrieve" value="Fetch" /></p> </form> <?php } // end if .jpg } // end while ?> Quote Link to comment https://forums.phpfreaks.com/topic/53777-semi-blog-with-php/#findComment-265878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.