Jump to content

Raider

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Raider's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey, thanks for the replies. I tried something similar to what you posted, Jonsjava, but the server I am using doesn't seem to like it. I'm not sure if it's running apache or not, and I don't know how to make it so that it interprets this file as a PHP file, yet has XML extension so that RSS readers don't complain. I added the & and it seems to work Thanks to both.
  2. Hi there. I'm trying to make an RSS feed for my website (a blog), but it seems harder than I anticipated. Right now, what I'm doing is executing a script once in a while which writes a full RSS feed (with updated articles and whatnot) to a file, rss.xml. All seems to be working correctly, except for one thing. When I use the <link></link> tags, I link to a page which looks like: index.php?a=001&aid=15. That is, it has arguments at the end. I've tried validating my RSS feed but it doesn't like the last bit (if I just use index.php for every link, no errors pop up). Any ideas on how I can fix this problem? Thanks
  3. Aha! Got it, finally. Yes, the error was with move_uploaded_file() => The problem was that I didn't have permissions to write to that directory. :'( Now it's all sorted out, images are uploading without any problem! Thank you so much, I really doubt I would have found this problem on my own so quickly.
  4. OK, so I added that bit of code, and I get the following: GET:Array ( [a] => 005 ) POST:Array ( [title] => fasf [description] => dasdf [article] => asdfasdf [src] => asdfasdf [articleIcon] => m.jpg [createArticle] => 1 [submit] => Create New Article ) FILES:Array ( [img1] => Array ( [name] => yo3.jpg [type] => image/jpeg [tmp_name] => /tmp/phpFzGv5v [error] => 0 [size] => 89804 ) [img2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [img3] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [img4] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [img5] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [img6] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [img7] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [img8] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) So, here I'm only trying to upload one image and no errors occur. However, when I log on to my FTP to see if it's actually uploaded it, it hasn't. *EDIT* The 'tmp' directory didn't exist, so I created it. It still doesn't work.
  5. What error are you getting? Where is it messing up?
  6. Hey. Thanks for the replies. I added error messages as well now, but I'm still a bit baffled. OK, so here's the form I'm using: <form name="form1" method="post" action="index.php?a=005" enctype="multipart/form-data"> <div class="articleContainerFullDiv"> <div class="articleGenericDiv"> Title:<br /><input type="text" name="title" class="form" id="title" value="" /> (<?php echo date('d, D / M / Y'); ?>) - Posted by <?php echo $_SESSION['user']; ?> </div> <div class="articleGenericDiv"> Description:<br /><textarea class="form" name="description" id="description" cols="80" rows="7"></textarea> </div> <div class="articleGenericDiv"> Article:<br /><textarea class="form" name="article" id="article" cols="80" rows="15"></textarea> </div> <div class="articleGenericDiv"> Source:<br /><input class="form" type="text" name="src" id="src" value="" /> </div> <div class="articleGenericDiv"> Image 1:<br /><input class="form" name="img1" id="img1" type="file" /> </div> <div class="articleGenericDiv"> Image 2:<br /><input class="form" name="img2" id="img2" type="file" /> </div> <div class="articleGenericDiv"> Image 3:<br /><input class="form" name="img3" id="img3" type="file" /> </div> <div class="articleGenericDiv"> Image 4:<br /><input class="form" name="img4" id="img4" type="file" /> </div> <div class="articleGenericDiv"> Image 5:<br /><input class="form" name="img5" id="img5" type="file" /> </div> <div class="articleGenericDiv"> Image 6:<br /><input class="form" name="img6" id="img6" type="file" /> </div> <div class="articleGenericDiv"> Image 7:<br /><input class="form" name="img7" id="img7" type="file" /> </div> <div class="articleGenericDiv"> Image 8:<br /><input class="form" name="img8" id="img8" type="file" /> </div> <div class="articleIconListContainerDiv"> <?php echo articles_displayIcons(); ?> </div> <div class="articleGenericDiv"> <input name="createArticle" type="hidden" value="1" /> <input name="submit" type="submit" class="form" id="submit" value="Create New Article" /> </div> </div> When submitted, the following function is executed: function articles_printFormCreate() { // Description: Prints the form to create a new article. // // Input Arguments: // NONE // Last Modified: Fabian Siddiqi (09 / 08 / 2009) if (!isset($_POST['createArticle'])) { include(FORMAT_ARTICLES_CREATE); } elseif (isset($_POST['createArticle'])) { if ($_POST['createArticle'] == 1) { $desc = mysql_real_escape_string($_POST["description"]); $a = mysql_real_escape_string($_POST["article"]); $t = mysql_real_escape_string($_POST["title"]); $s = mysql_real_escape_string($_POST["src"]); $u = mysql_real_escape_string($_SESSION["id"]); $i = $_POST['articleIcon']; $d = time(); articles_upload(); mysql_query("INSERT INTO articles (`id`, `title`, `description`, `article`, `user`, `src`, `date`, `likes`, `dislikes`, `views`, `icon`, `trash`, `published`) VALUES (NULL, '$t', '$desc', '$a', '$u', '$s', '$d', '0', '0', '0', '$i', '0', '0')"); } } } The 'articles_upload()' function is as follows: function articles_upload() { // Description: Uploads images if an article is modified or created. // // Input Arguments: // NONE // Last Modified: Fabian Siddiqi (09 / 08 / 2009) // Allowed formats. $allowed = array('image/bmp', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/svg+xml', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-greymap', 'image/x-portable-pixmap'); // Repeat process for all 8 images. First check if file is being uploaded, then check if there are any errors. If not, check // file size and type. Then, if all is OK, upload. echo "Trying to upload files..."; for ($i = 1; $i < 9; $i++) { $img = 'img' . $i; if (isset($_FILES[$img])) { if (!($_FILES[$img]['error'] > 0)) { if (in_array($_FILES[$img]['type'], $allowed)) { if ($_FILES[$img]['size'] < 1000000) { if (file_exists("images/articleImages/" . $_FILES[$img]['name'])) { echo "Error: File with the same name already exists."; } else { move_uploaded_file($_FILES[$img]['tmp_name'], "images/articleImages/" . $_FILES[$img]['name']); if (file_exists("images/articleImages/" . $_FILES[$img]['name'])) { echo "Image successfully uploaded<br />"; } } } else { echo "Error: File too big.<br />"; } } else { echo "Error: Filetype not allowed.<br />"; } } else { echo "Error: " . $_FILES[$img]['error']; } } else { echo "Error: '$img' does not have a value.<br />"; } } } When I create an article, everything works fine (a new row is added to the database as expected). Problems arise when actually trying to upload an image. The error I receive is that $_FILES[$img]['error'] is not 0. I get an error code of 4 which, from what I've read on the PHP website, is: "Value: 4; No file was uploaded." I have no idea what exactly this means. At first I thought that I couldn't write to the server, but then I saw there was another error 7 means "Could not write to disk" which would be a more appropriate error if that were the case.
  7. Hi! I've created a simple blogging infrastructure. I've been using WAMP to test it and everything seemed fine. However, now I've bought a domain and have some server space, but there's a function that doesn't seem to work: uploading images. When you write an article, I give the option to upload images and use PHP to upload to the correct folder and use the correct filename. This is the code I'm using: for ($i = 1; $i < 9; $i++) { $img = 'img' . $i; if (isset($_FILES[$img])) { if (!($_FILES[$img]['error'] > 0)) { if (in_array($_FILES[$img]['type'], $allowed)) { if ($_FILES[$img]['size'] < 1000000) { if (file_exists("images/articleImages/" . $_FILES[$img]['name'])) { echo "An image already exists with the same name as image $i: " . $_FILES[$img]['name']; echo "<br />"; } else { move_uploaded_file($_FILES[$img]['tmp_name'], "images/articleImages/" . $_FILES[$img]["name"]); echo "Successfully uploaded image $i<br />"; } } } } } } $allowed just contains acceptable file formats (image/bmp, image/gif, image/jpg, etc.). I have a for loop because you have the ability to upload up to eight images. The HTML code I am using for the file upload section of the form is: <input class="form" name="img1" id="img1" type="file" /> This code is repeated eight times, and the fields are called img2, img3, img4, etc... I have no idea why it isn't working on the new server. The article is published correctly, but the selected files aren't uploaded (this DOES work on my own computer, using WAMP). Any ideas as to why this is freaking out? Thanks
  8. Sorry for taking so long to reply. Thanks a lot for that information. Your reply is definitely helpful, now I know where to start reading (SEO). What you're saying makes sense. Again, thanks for the reply.
  9. I'm not sure if I correctly understand, but here goes. When you use LIMIT with MySQL queries, you can put one or two numbers afterwards. The first number is the row from which it should start, and the second number is the amount of rows it should count from the starting point (first number). Example: mysql_query("SELECT * FROM my_table LIMIT 5,5"); That will select all columns from 'my_table'. However, it will start at row 5 and take 5 rows from there, i.e., it will take rows 6, 7, 8, 9, 10. mysql_query("SELECT * FROM my_table LIMIT 0,5"); That will get rows 1, 2, 3, 4, 5.
  10. Hi there. I've written up a website using PHP/MySQL which we're using as a blogging platform. All articles (and their information: small description, title, user, etc.) are kept within one table. The system is set up such that you go to index.php?article_id=12 (for example) to read the article whose ID is 12. However, we've realized that it's probably impossible for search engines to index all these articles (since they're inside the DB) so that we have a higher chance of appearing when someone searches for something relevant. Is there any simple and efficient way of solving this problem? Thanks in advance
  11. Thanks I haven't coded much (if at all) related to the tags part of my website, so I'll probably just make a new table for them. Again, thanks a lot!
  12. Hey guys. I don't think the title is very informative but was unable to phrase it correctly and concisely; sorry about that. Here's the longer description: I wanted to make a query to a DB which only selects rows in which one of the columns contains a string (even if in that column there are other strings / words seperated by spaces). Basically, one of the columns of my table is called "tags", which, as the name indicates, contains various tags. A coouple of example rows: ID (int): 1 NAME (text): "My article" TAGS (text): "tag1, tag3" ID (int): 2 NAME (text): "My article2" TAGS (text): "tag2, tag4" So I want to select, for example, all rows that contain "tag1" in the "tags" column, even if it isn't the only tag. Something like: SELECT * FROM my_table WHERE tags = * . "tag1" . * but that syntax does not work. Thanks a lot in advance.
  13. OK, that makes a lot of sense! Thanks a lot. I've modified the function to accept the arguments and just passed 'em on in test.php (so I didn't make $cfg global). Works fine now. Thanks a lot for the quick reply!
  14. Hi! It's been a while since I've programmed in PHP / MySQL, so please bear with me. I'm having problems connecting to my MySQL database (which has been created and all, using PhpMyAdmin). Here's the code: globalvariables.php $cfg["db"]["name"] = "fabiansat_info"; $cfg["db"]["username"] = "fabiansat_u"; $cfg["db"]["password"] = "aaaa"; $cfg["db"]["host"] = "localhost"; includes/database.php function connect_db() { $conn = mysql_connect($cfg["db"]["host"], $cfg["db"]["username"], $cfg["db"]["password"]) or die (mysql_error()); if ($conn) echo "Connection successful!"; mysql_select_db($cfg["db"]["name"]); } test.php include('globalvariables.php'); include('includes/database.php'); connect_db(); The error I get is the following: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vhostswww'@'localhost' (using password: NO) in /www/vndv.com/f/a/b/fabiansat/htdocs/includes/database.php on line 28 Access denied for user 'vhostswww'@'localhost' (using password: NO) If I change the $cfg["db"]["host"], etc. part in the connect_db() funciton and explicitly state write the username, password, host, etc. it works fine. Thanks
×
×
  • 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.