login  Naam:   Wachtwoord: 
Registreer je!
 Forum

upload script

Offline Ultimatum - 26/10/2005 02:59 (laatste wijziging 26/10/2005 03:02)
Avatar van UltimatumPHP expert heb ergens dit upload script van geplukt alleen hij maakt alle images in mijn members map aan terwijl het in de submap images van members moet :-)

iemand die zo aardig is om mij te helpen 

  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <center>
  6. <form enctype="multipart/form-data" action="upload.php" method="POST">
  7. Send this file: <input name="file" type="file" /><br />
  8. <input type="submit" name="upload" value="Upload File" />
  9. </form>
  10. </center>
  11. </body>
  12. </html>
  13.  
  14. <center>
  15.  
  16. <?php
  17. if(isset($_POST['upload'])) {
  18.  
  19. function generate_rand($l){
  20. $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  21. srand((double)microtime()*1000000);
  22. for($i=0; $i<$l; $i++)
  23. {
  24. $rand.= $c[rand()%strlen($c)];
  25. }
  26. return $rand;
  27. }
  28.  
  29. $uploaddir = "./";
  30. $maxfilesize = 1048576;
  31. $filename = $_FILES['file']['name'];
  32. $filesize = $_FILES['file']['size'];
  33. $filetmpname = $_FILES['file']['tmp_name'];
  34. $valid = array (".jpg",".gif",".png");
  35. $max_width = 300;
  36. $max_height = 300;
  37.  
  38. if ($filename) {
  39. $error = "";
  40. if ($filesize == 0) {
  41. $error .= "The submitted file was invalid.<br />";
  42. }
  43. $type = strtolower(strstr($filename, '.'));
  44. if (!in_array($type, $valid)) {
  45. $error .= "The submitted file was of invalid type.<br />";
  46. }
  47. if ($filesize>$maxfilesize) {
  48. $error .= "The submitted file was larger than a Megabyte.<br />";
  49. }
  50. list($width, $height, $t, $w) = getimagesize($filetmpname);
  51.  
  52. if ($width > $max_width|$height > $max_height) {
  53. $error .= "The image dimensions are larger than the maximum dimensions(".$max_width."x".$max_height.")";
  54. }
  55.  
  56. $randnum = generate_rand(10);
  57. $randnum .= $type;
  58. $file_exists = true;
  59. while ($file_exists) {
  60. if (file_exists("$uploaddir$randnum")) {
  61. $randnum = generate_rand(10);
  62. $randnum .= $type;
  63. }else{
  64. $file_exists = false;
  65. }
  66. }
  67. if ($error == "") {
  68. if (move_uploaded_file($filetmpname, "$uploaddir$randnum")) {
  69. chmod("$uploaddir$randnum", 0644);
  70. echo "Your file was successfully uploaded!<br />";
  71. echo "<a href='.$uploaddir$randnum.'>Click here to go to your upload!</a>";
  72. } else {
  73. echo "Your file could not be uploaded.";
  74. }
  75. }else{
  76. echo $error;
  77. }
  78. }else{
  79. echo "No file was uploaded";
  80. }
  81. }
  82. ?>
  83. </center>

5 antwoorden

Gesponsorde links
Offline Ch0coschijt - 26/10/2005 05:06
Avatar van Ch0coschijt HTML interesse moet je dan niet gewoon effe
  1. $uploaddir = "./";


aanpassen?
Offline Gerard - 26/10/2005 11:28
Avatar van Gerard Ouwe rakker PEBCAC ;/
Offline Ultimatum - 26/10/2005 13:34 (laatste wijziging 26/10/2005 14:02)
Avatar van Ultimatum PHP expert @ch0coschijt dan krigj ik deze error
Citaat:
Warning: move_uploaded_file(members/images/qCpwn1MRD0.jpg): failed to open stream: No such file or directory in /usr/export/www/vhosts/funnetwork/hosting/ultimatum/members/upload.php on line 68

Warning: move_uploaded_file(): Unable to move '/usr/export/tmp/php1tfJwE' to 'members/images/qCpwn1MRD0.jpg' in /usr/export/www/vhosts/funnetwork/hosting/ultimatum/members/upload.php on line 68
Your file could not be uploaded.


@Proximus begreep van ch0coschijt's post meer dan die van jou 
Offline Gerard - 26/10/2005 13:44
Avatar van Gerard Ouwe rakker 1. Variabelen buiten de quotes
2. Zorg dat je upload.php de juiste chmod heeft
3. PEBCAC = Problem Exists Between Computer and Chair
Offline Ultimatum - 26/10/2005 13:50 (laatste wijziging 26/10/2005 18:29)
Avatar van Ultimatum PHP expert ok, maar waarom moet upload juiste cmod hebben dan, want dat is toCH gewoon het script om up te loaden..
:\

edit:
@VinTage, er zate nog veel meer fouten in (stuk of 5), deze over het hoofd gezien 

edit: niemand.. 
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.219s