Hello Guys

i'm still on the images and uploading. and since not having worked on this before i'm really struggling.

i found this script:

PHP: Upload and resize image script ( http://www.theopensurgery.com/29/php-upload-and-resize-image-script/ )

<form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
        <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);

          $imagepath = $imagename;
          $save = "images/" . $imagepath; //This is the new file you saving
          $file = "images/" . $imagepath; //This is the original file

          list($width, $height) = getimagesize($file) ; 

          $modwidth = 150; 

          $diff = $width / $modwidth;

          $modheight = $height / $diff; 
          $tn = imagecreatetruecolor($modwidth, $modheight) ; 
          $image = imagecreatefromjpeg($file) ; 
          imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 

          imagejpeg($tn, $save, 100) ; 

          $save = "images/sml_" . $imagepath; //This is the new file you saving
          $file = "images/" . $imagepath; //This is the original file

          list($width, $height) = getimagesize($file) ; 

          $modwidth = 80; 

          $diff = $width / $modwidth;

          $modheight = $height / $diff; 
          $tn = imagecreatetruecolor($modwidth, $modheight) ; 
          $image = imagecreatefromjpeg($file) ; 
          imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 

          imagejpeg($tn, $save, 100) ; 
        echo "Large image: <img src='images/".$imagepath."'><br>"; 
        echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 

      }
    }
?> 

I've copied it and made an images directory in my root of my server and tried running it. and i got this whole list of errors.

Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 17

Warning: Division by zero in D:\wamp\www\alphaVer3\upload-size.php on line 23

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in D:\wamp\www\alphaVer3\upload-size.php on line 24

Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 25

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 26

Warning: imagejpeg(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 28

Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 33

Warning: Division by zero in D:\wamp\www\alphaVer3\upload-size.php on line 39

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in D:\wamp\www\alphaVer3\upload-size.php on line 40

Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 41

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 42

Warning: imagejpeg(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 44
Large image: ( Broken Image )
Thumbnail: ( Broken image )

I also want to make it so it will resize the photo in 3 versions. a big photo with a 500 pixel long side, a medium photo with a 195 pixel longside and a thumbnail with a 80 pixel long side.
and then read the image filename with the path into a database.

can someone please shed some light on this for me please!

Thanks

    is it a defined variable? $server['php-self']
    you've better use the $
    SERVER['PHP_SELF']

                  $imagename = basename($_FILES['new_image']['name']);
                  $source = $_FILES['new_image']['tmp_name'];
                  $target = "images/".$imagename;
                  move_uploaded_file($source, $target); 
      djjjozsi;10916434 wrote:

      is it a defined variable? $server['php-self']
      you've better use the $
      SERVER['PHP_SELF']

                    $imagename = basename($_FILES['new_image']['name']);
                    $source = $_FILES['new_image']['tmp_name'];
                    $target = "images/".$imagename;
                    move_uploaded_file($source, $target); 

      Thanks i did that here is the code now

      <form action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
              <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
              <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
      </form>
      <?php
              if(isset($_POST['submit'])){
                if (isset ($_FILES['new_image'])){
                    $imagename = basename($_FILES['new_image']['name']);
                    $source = $_FILES['new_image']['tmp_name'];
                    $target = "images/".$imagename;
                    move_uploaded_file($source, $target);
      
                $imagepath = $imagename;
                $save = "images/" . $imagepath; //This is the new file you saving
                $file = "images/" . $imagepath; //This is the original file
      
                list($width, $height) = getimagesize($file) ; 
      
                $modwidth = 150; 
      
                $diff = $width / $modwidth;
      
                $modheight = $height / $diff; 
                $tn = imagecreatetruecolor($modwidth, $modheight) ; 
                $image = imagecreatefromjpeg($file) ; 
                imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
      
                imagejpeg($tn, $save, 100) ; 
      
                $save = "images/sml_" . $imagepath; //This is the new file you saving
                $file = "images/" . $imagepath; //This is the original file
      
                list($width, $height) = getimagesize($file) ; 
      
                $modwidth = 80; 
      
                $diff = $width / $modwidth;
      
                $modheight = $height / $diff; 
                $tn = imagecreatetruecolor($modwidth, $modheight) ; 
                $image = imagecreatefromjpeg($file) ; 
                imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
      
                imagejpeg($tn, $save, 100) ; 
              echo "Large image: <img src='images/".$imagepath."'><br>"; 
              echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 
      
            }
          }
      ?>
      

      But it still giving me the same errors...

      Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 17

      Warning: Division by zero in D:\wamp\www\alphaVer3\upload-size.php on line 23

      Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in D:\wamp\www\alphaVer3\upload-size.php on line 24

      Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 25

      Warning: imagecopyresampled(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 26

      Warning: imagejpeg(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 28

      Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 33

      Warning: Division by zero in D:\wamp\www\alphaVer3\upload-size.php on line 39

      Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in D:\wamp\www\alphaVer3\upload-size.php on line 40

      Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in D:\wamp\www\alphaVer3\upload-size.php on line 41

      Warning: imagecopyresampled(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 42

      Warning: imagejpeg(): supplied argument is not a valid Image resource in D:\wamp\www\alphaVer3\upload-size.php on line 44
      Large image: ( Broken image link )
      Thumbnail: ( Broken image link )

        there is no images folder next to your .php file

        or you did not set the 'write' permit.

                  if (isset ($_FILES['new_image'])){
                  if(!file_exists("images"))
                  {
        		  mkdir("images" , "0744") or die("Could not create images folder");
        		  die("folder created!");
                  }
          djjjozsi;10916446 wrote:

          there is no images folder next to your .php file

          or you did not set the 'write' permit.

                    if (isset ($_FILES['new_image'])){
                    if(!file_exists("images"))
                    {
          		  mkdir("images" , "0744") or die("Could not create images folder");
          		  die("folder created!");
                    }

          ok i went and copied the file on my server in a subdomain. the file seems to be uploading to the website but then for some reason it doesnt get there in the end.

          i made an images folder in the root and gave it full write permisions (777)

          i then run the script where it was uploading the file ( could see the 5 meg traffic going through the router ) but then once again it gave me the same problem...

          Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 17

          Warning: Division by zero in /home/alphanig/public_html/testserver/upload-size.php on line 23

          Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/alphanig/public_html/testserver/upload-size.php on line 24

          Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 25

          Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 26

          Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 28

          Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 33

          Warning: Division by zero in /home/alphanig/public_html/testserver/upload-size.php on line 39

          Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/alphanig/public_html/testserver/upload-size.php on line 40

          Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 41

          Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 42

          Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 44
          Large image: ( again a broken link )
          Thumbnail: ( again a broken link )

          the file is in my root of the test domain and also is the folder.

          http://testserver.alphanightlife.co.za/upload-size.php
          http://testserver.alphanightlife.co.za/images/

          and this is the code now...

          <form action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
                  <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
                  <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
          </form>
          <?php
                  if(isset($_POST['submit'])){
                    if (isset ($_FILES['new_image'])){
          		  	  if(!file_exists("images"))
          				  {
          				  mkdir("images" , "0744") or die("Could not create images folder");
          				  die("folder created!");
          				  } 
          			  $imagename = basename($_FILES['new_image']['name']);
                        $source = $_FILES['new_image']['tmp_name'];
                        $target = "images/".$imagename;
                        move_uploaded_file($source, $target);
          
                    $imagepath = $imagename;
                    $save = "images/" . $imagepath; //This is the new file you saving
                    $file = "images/" . $imagepath; //This is the original file
          
                    list($width, $height) = getimagesize($file) ; 
          
                    $modwidth = 150; 
          
                    $diff = $width / $modwidth;
          
                    $modheight = $height / $diff; 
                    $tn = imagecreatetruecolor($modwidth, $modheight) ; 
                    $image = imagecreatefromjpeg($file) ; 
                    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
          
                    imagejpeg($tn, $save, 100) ; 
          
                    $save = "images/sml_" . $imagepath; //This is the new file you saving
                    $file = "images/" . $imagepath; //This is the original file
          
                    list($width, $height) = getimagesize($file) ; 
          
                    $modwidth = 80; 
          
                    $diff = $width / $modwidth;
          
                    $modheight = $height / $diff; 
                    $tn = imagecreatetruecolor($modwidth, $modheight) ; 
                    $image = imagecreatefromjpeg($file) ; 
                    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
          
                    imagejpeg($tn, $save, 100) ; 
                  echo "Large image: <img src='images/".$imagepath."'><br>"; 
                  echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 
          
                }
              }
          ?>
          

            [its ok for me... did you repaired something ?

              you know what i think its been limited with my config file i just used a 300kb file and it worked.

              but thanks for your help! its uploading!

              now back to the part that i need to make 3 images preferably with random names...

              1. large image of 500 pixels on the long side
              2. medium image of 195 pixels on the long side
              3. the thumb of 80 pixels on the long side.

              4 work in an image size checker...

              thanks for your help djjjozsi

                OK after a weekend of struggling i manage to work it out here the code is now.

                <form action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
                        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
                        <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
                </form>
                <?php
                        if(isset($_POST['submit'])){
                          if (isset ($_FILES['new_image'])){
                		  	  		  $imagename = basename($_FILES['new_image']['name']);
                					  $source = $_FILES['new_image']['tmp_name'];
                					  $target = "gfx/profilephotos/".$imagename;
                					  move_uploaded_file($source, $target);
                
                				  $imagepath = $imagename;
                				  $save = "gfx/profilephotos/" . $imagepath; //This is the new file you saving
                				  $file = "gfx/profilephotos/" . $imagepath; //This is the original file
                
                				  list($width, $height) = getimagesize($file) ; 
                
                				  $largeimage=500; //sets the longest side
                
                				  $imgratio=$width/$height; //works out the image ratio and if its a portrait or landscape
                					if ($imgratio>1){ //tests if it is a landscape
                						$newwidth = $largeimage; //sets the longest side for landscape
                						$newheight = $largeimage/$imgratio; //calculate the shortest side for landscape
                						}else{
                								$newheight = $largeimage; //sets the longest side for Portrait
                								$newwidth = $largeimage*$imgratio; //calculate the shortest side for Portrait
                								}
                
                				  $tn = imagecreatetruecolor($newwidth, $newheight) ; 
                				  $image = imagecreatefromjpeg($file) ; 
                				  imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ; 
                
                				  imagejpeg($tn, $save, 100) ; 
                
                				  $save = "gfx/profilephotos/med_" . $imagepath; //This is the new file you saving
                				  $file = "gfx/profilephotos/" . $imagepath; //This is the original file
                
                				  list($width, $height) = getimagesize($file) ; 
                
                				  $mediumimage=195;
                
                				  $imgratio=$width/$height;
                					if ($imgratio>1){
                						$newwidth = $mediumimage;
                						$newheight = $mediumimage/$imgratio;
                						}else{
                								$newheight = $mediumimage;
                								$newwidth = $mediumimage*$imgratio;
                								}
                
                				  $tn = imagecreatetruecolor($newwidth, $newheight) ; 
                				  $image = imagecreatefromjpeg($file) ; 
                				  imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ; 
                
                				  imagejpeg($tn, $save, 100) ; 
                
                				  $save = "gfx/profilephotos/thumb_" . $imagepath; //This is the new file you saving
                				  $file = "gfx/profilephotos/" . $imagepath; //This is the original file
                
                				  list($width, $height) = getimagesize($file) ; 
                
                				  $thumbimage=80;
                
                				  $imgratio=$width/$height;
                					if ($imgratio>1){
                						$newwidth = $thumbimage;
                						$newheight = $thumbimage/$imgratio;
                						}else{
                								$newheight = $thumbimage;
                								$newwidth = $thumbimage*$imgratio;
                								}
                
                				  $tn = imagecreatetruecolor($newwidth, $newheight) ; 
                				  $image = imagecreatefromjpeg($file) ; 
                				  imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ; 
                
                				  imagejpeg($tn, $save, 100) ; 
                
                				echo "Large image: <img src='gfx/profilephotos/".$imagepath."'><br>"; 
                				echo "Medium: <img src='gfx/profilephotos/med_".$imagepath."'>";
                				echo "Thumbnail: <img src='gfx/profilephotos/thumb_".$imagepath."'>"; 
                
                      }
                    }
                ?>
                
                  Write a Reply...