Jump to content

John_S

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

John_S's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you! Worked like a charm!
  2. Hey there! I was asking myself the same question quite some time ago and I found for my self that the answer is yes. Even if in the beginning it might appear frustrating and complicated, once you've learned a framework, your coding will become faster and your code will be easier to read and more structured. However, once you decided to switch to a framework, I strongly suggest you to check out several frameworks at once, and not stopping on the most popular one. Because some popular frameworks might appear interesting, but when you learn out about them, they might appear limited. Another idea might be coding your own framework, using MVC pattern and inspiring you from already existent frameworks. It not only allows you to better understand common used patterns but also create a framework that suits your needs. Some frameworks that would suggest for a beginner: CodeIgniter, Kohana (version 2.x.x, rather than version 3.x because HMVC pattern used in 3.x might be a bit too complicated to understand in the beginning), Cake and Fuse. Hope it helps! John_S
  3. Greetings! Recently I've been reading some php articles, and I found one with an interesting script concept but with an impossibly huge MySQL query which doesn't seem to work, unfortunately complicated MySQL queries aren't my cup of tea, so I wasn't able to fix it, that's why I am here hoping that somebody could help me to solve it. SELECT options.id, options.value, COUNT(*) AS votes FROM votes, FROM 'options' WHERE options.id = votes.option_id AND votes.option_id IN(SELECT id FROM options WHERE ques_id='1') GROUP BY votes.option_id Thank you a lot in advance! John_S
  4. For some reason I couldn't find the way how to format the code correctly, but doesn't matter. Thanks anyway.
  5. That is what I am trying to do, and about the error, I don't get any at all, that's the problem. No error at all but the files are not created in the folders.
  6. Hello everybody,I have recently created an image upload script which not only uploads and resizes the image but also creates a small thumbnail. After that the script saves both thumb and the resized image in two different folders and adds the information into the database. However when I try to test it, I receive an error. Can somebody please help me and tell me what's wrong? I've checked everything but it seems I am either blind or simply can't see the error. Here is my code: <?phpif ((isset($_POST["image_upload"])) && ($_POST["submitted_form"] == "image_upload_form")) { // file needs to be jpg,gif,png and 4 MB max if (($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg" || $_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/png") || $_FILES["image"]["type"] == "image/bmp" && ($_FILES["image"]["size"] < 4000000)) { // some settings $max_upload_width = 550; $max_upload_height = 550; // if uploaded image was JPG/JPEG if($_FILES["image_upload"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg") { $image_source = imagecreatefromjpeg($_FILES["image_upload"]["tmp_name"]); $extension = '.jpeg'; } // if uploaded image was GIF if($_FILES["image_upload"]["type"] == "image/gif") { $image_source = imagecreatefromgif($_FILES["image_upload"]["tmp_name"]); $extension = '.gif'; } // if uploaded image was PNG if($_FILES["image_upload"]["type"] == "image/png") { $image_source = imagecreatefrompng($_FILES["image_upload"]["tmp_name"]); $extension = '.png'; } //If uploaded file was BMP. if($_FILES["image_upload"]["type"] == "image/png") { $image_source = imagecreatefromwbmp($_FILES["image_upload"]["tmp_name"]); $extension = '.bmp'; } $thumnail_name = $_FILES["image_upload"]["name"]; ///////////////////////////////// // Transform the main image. ///////////////////////////////// $_FILES["image_upload"]["name"] = uniqid().$extension; $remote_file = "images/uploads/".$_FILES["image_upload"]["name"]; imagepng($image_source, $remote_file, 100); chmod($remote_file, 0755); // Get width and height of original image list($image_width, $image_height) = getimagesize($remote_file); if($image_width>$max_upload_width || $image_height >$max_upload_height) { $proportions = $image_width/$image_height; if($image_width>$image_height){$new_width = $max_upload_width; $new_height = round($max_upload_width/$proportions); } else{ $new_height = $max_upload_height; $new_width = round($max_upload_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefrompng($remote_file); } imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_file,100); imagedestroy($new_image); imagedestroy($image_source); ///////////////////////////////// // Transform the thumbnail image. ///////////////////////////////// $max_thumb_width = 90; $max_thumb_height = 90; //The procedure. $thumnail_name = uniqid()."_thumb".$extension; $remote_thumbnail = "images/uploads/thumbs/".$thumnail_name; imagepng($thumbnail_source, $remote_thumbnail, 100); chmod($remote_thumbnail,0755); // Get width and height of original image list($image_width, $image_height) = getimagesize($remote_thumbnail); if($image_width>$max_thumb_width || $image_height >$max_thumb_height) { $proportions = $image_width/$image_height; if($image_width>$image_height){ $new_width = $max_thumb_width; $new_height = round($max_thumb_width/$proportions); } else{ $new_height = $max_thumb_height; $new_width = round($max_thumb_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefrompng($remote_thumbnail); } imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_thumbnail,100); imagedestroy($new_image); imagedestroy($image_source); $db->query("INSERT INTO uploads_images (id,name,url,thumb_url,added_by,date) VALUES (NULL,'".$_FILES["image_upload"]["name"]."','".$remote_file."','".$remote_thumbnail."','".$mybb->user['username']."', '".$date."')"); echo '<blockquote class="green">Image uploaded successfully!</blockquote>'; } else { echo '<blockquote class="red">An error was encountered during the image transfer. Please make sure the file is jpg, gif, png or bmp and that is smaller than 4MB! !</blockquote>'; }}?> <h1 style="margin-bottom: 0px">Submit an image</h1> <div class="article"><div class="article_content"><p>Browse for the file you want to upload and click "Upload".</p> <form action="uploads.php" method="post" enctype="multipart/form-data" name="image_upload" id="image_upload" style="margin-bottom:0px;"> <label>Your file, maximum 4MB. it can be jpg, gif, png:</label><br /> <input name="image_upload" type="file" id="image" size="40" /> <input type="submit" name="submit" value="Upload image" /> <input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" /></form> <?php if(isset($remote_thumbnail)) { echo '<p><center><a href="'.$remote_thumbnail.'" rel="lightbox"><img src="'.$remote_thumbnail.'" alt="Picture of the week" /></a></center><br /></p>';}?> </div></div>
  7. Hello everybody,I am trying to write a function which would work similarly to a cron job, each time a visitor will come to my site, the cron function will be called and will check if there is a cronjob to execute. I want to store all the cronjobs within a flat file so there won't be too many connections to the database. However when I test my function it refuses to work, it doesn't output any errors at all, but there is no result displayed neither the flat file database is changed. Could somebody please tell me what's wrong? Here's my code: function cron($name) { $file = file('./crons/crons.db.php'); foreach ($file as $line) { if(ereg("$name", $line)) { $cronjob = explode("|", $line); if (time() >= $cronjob[2]) { include("./crons/$name.cron.php"); } } } // End of Foreach $source = fopen('./crons/crons.db.php', w); foreach ($file as $line) { if(!ereg("$name", $line)) { fwrite($source, $line); } else { $lastrun = time(); $toberun = time() + (24 * 60 * 60); fwrite($source, "|$name|$lastrun|$toberun|$status| "); } } } // End of Fucntion In my files, I call the function like this: cron("db_backup"); [db_backup = databse backup.] Thanks a lot in advance!Yours John_S
  8. Thanks a lot! Yes indded by default the display_error was set to off, and I didn't notice until now. Thanks a lot for your code, it worked exactly as I needed
  9. Hello there, Thanks a lot for your help but sadly when I try that code, I don't have any display at all, the page is blank. Is that normal?
  10. Hello there, Thanks a lot for your answer! Well I actually manage to isolate the table I need, the problem I have is to get the pieces of information that I need from the table rows. I don't get how to do it
  11. Hello there everybody! As the title says I am searching a way to get content from a table on an external webpage. I tried what I could but without any results. I proceeded this way:First I get content from the page with: <?php $source = file_get_contents('URL'); ?> Then I isolate the table I need the info from: <?phppreg_match_all('#<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1 WIDTH=100%>(.*?)</TABLE>#s', $source, $entries); But when I arrive there, I don't know how to extract table rows and the info I need. The structure of a table row looks like <TR BGCOLOR=" DEPENDS ON THE ROW "><TD WIDTH=10%>Info I need 1</TD><TD WIDTH=55%><A HREF=" AN URL">Info I need 2</A></TD><TD WIDTH=15%>Info I need 3</TD><TD WIDTH=20%>Info I need 4</TD></TR> Does anybody know how I can get that info? Thanks a lot in advance!Yours John_S
  12. Hello there, When I run your code, I receive this : Line 1: <?php die("Access Restricted. You are not allowed to access this file"); ?> Id|Username|Password|Permissions|Last Logged In|Email|Registered| Seems weird to me actually. And when myself I execute my script I got a blank browser window => no output at all. Might it be because the content is "technically" on the same line? (In my editor I see it on two lines but it might be on one if there isn't a proper ) EDIT: Thanks a lot! Your part of code made me realize that two pices <?php... and id|username... were "technically" on the same line since I had "\n"s everywhere but not "\r"s. So even thought I saw the code in my editor being on two different lines, it wasn't like that in the file itself.
  13. Hello everybody, I have a little problem with a small part of code: $users = file("users.db.php"); foreach ($users as $line) { if(!eregi("<\?php",$line)) { $user = explode('|', $line); echo $user[0]."\n".$user[1]."\n".$user[2]."\n".$user[3]."\n".$user[4]; } } I am trying to get out all lines from a file except all lines that start with <?php, the problem is... it doesn't work, it doesn't print anything at all. In that file (users.db.php) I have the following code: <?php die("Access Restricted. You are not allowed to access this file"); ?> Id|Username|Password|Permissions|Last Logged In|Email|Registered| Could somebody tell me please where is my mistake? Thanks a lot in advance!
  14. Thanks! A lot True, but it is allowed (well as far as I know ), a friend of mine uses a specific folder with a txt file for each entry, but personally I think that would be a bit too messy
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.