Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SQL][PHP]dodawanie obrazu
retes
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.04.2010

Ostrzeżenie: (0%)
-----


tak wygląda kod,
nie mogę załadować obrazu, wydaje mi się że bląd tkwić może w ściezce- linia 39, lub coś jestz plikiem temp, możecie pomóc?



  1. <?php
  2.  
  3.  
  4. include("config.php");
  5. include("functions.php");
  6.  
  7. $db = mysql_connect($dbhost, $dbuser, $dbpassword);
  8. mysql_select_db($dbdatabase, $db);
  9.  
  10. $validid = pf_validate_number($_GET['id'], "redirect", "index.php");
  11.  
  12. if(isset($_SESSION['USERNAME']) == FALSE) {
  13. header("Location: " . $HOST_NAME . "login.php?ref=images&id=" . $validid);
  14. }
  15.  
  16. $theitemsql = "SELECT user_id FROM items WHERE id = " . $validid . ";";
  17. $theitemresult = mysql_query($theitemsql);
  18. $theitemrow = mysql_fetch_assoc($theitemresult);
  19.  
  20. if($theitemrow['user_id'] != $_SESSION['USERID']) {
  21. header("Location: " . $config_basedir);
  22. }
  23.  
  24. if($_POST['submit']) {
  25. if($_FILES['userfile']['name'] == '') {
  26. header("Location: " . $HOST_NAME . $SCRIPT_NAME . "?error=nophoto");
  27. }
  28. elseif($_FILES['userfile']['size'] == 0) {
  29. header("Location: " . $HOST_NAME . $SCRIPT_NAME . "?error=photoprob");
  30. }
  31. elseif($_FILES['userfile']['size'] > $MAX_FILE_SIZE) {
  32. header("Location: " . $HOST_NAME . $SCRIPT_NAME . "?error=large");
  33. }
  34. elseif(!getimagesize($_FILES['userfile']['tmp_name'])) {
  35. header("Location: " . $HOST_NAME . $SCRIPT_NAME . "?error=invalid");
  36. }
  37. else {
  38. $uploaddir = "C:/xampp/htdocs/sites/auction/images/";
  39. $uploadfile = $uploaddir . $_FILES['userfile']['name'];
  40.  
  41. if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  42.  
  43. $inssql = "INSERT INTO images(item_id, name) VALUES(" . $validid . ", '" . $_FILES['userfile']['name'] . "')";
  44. mysql_query($inssql);
  45.  
  46. header("Location: " . $HOST_NAME . $SCRIPT_NAME . "?id=" . $validid);
  47. }
  48. else {
  49. echo 'There was a problem uploading your file.<br />';
  50. }
  51. }
  52. }
  53. else {
  54. require("header.php");
  55.  
  56. $imagessql = "SELECT * FROM images WHERE item_id = " . $validid . ";";
  57. $imagesresult = mysql_query($imagessql);
  58. $imagesnumrows = mysql_num_rows($imagesresult);
  59.  
  60. echo "<h1>Current images</h1>";
  61.  
  62. if($imagesnumrows == 0) {
  63. echo "No images.";
  64. }
  65. else {
  66. echo "<table>";
  67. while($imagesrow = mysql_fetch_assoc($imagesresult)) {
  68. echo "<tr>";
  69. echo "<td><img src='" . $config_basedir . "/images/" . $imagesrow['name'] . "' width='100'></td>";
  70. echo "<td>[<a href='deleteimage.php?image_id=" . $imagesrow['id'] . "&item_id=" . $validid . "'>delete</a>]</td>";
  71. echo "</tr>";
  72. }
  73. echo "</table>";
  74. }
  75. switch($_GET['error']) {
  76. case "empty":
  77. echo 'You did not select anything.';
  78. break;
  79.  
  80. case "nophoto":
  81. echo 'You did not select a photo to upload.';
  82. break;
  83.  
  84. case "photoprob":
  85. echo 'There appears to be a problem with the photo your are uploading';
  86. break;
  87.  
  88. case "large":
  89. echo 'The photo you selected is too large';
  90. break;
  91.  
  92. case "invalid":
  93. echo 'The photo you selected is not a valid image file';
  94. break;
  95. }
  96.  
  97. ?>
  98.  
  99. <form enctype="multipart/form-data" action="<?php pf_script_with_get($SCRIPT_NAME); ?>" method="POST">
  100. <input type="hidden" name="MAX_FILE_SIZE" value="3000000">
  101. <table>
  102. <tr>
  103. <td>Image to upload</td>
  104. <td><input name="userfile" type="file"></td>
  105. </tr>
  106. <tr>
  107. <td><input type="submit" name="submit" value="Upload File"></td>
  108. </tr>
  109. </table>
  110. </form>
  111.  
  112. When you have finished adding photos, go and <a href="<?php echo "itemdetails.php?id=" . $validid; ?>">see your item</a>!
  113. <?php
  114. }
  115.  
  116. require("footer.php");
  117. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 04:25