Jump to content

Recommended Posts

Im getting lots of errors on my image uploading script, but i can't figure out why they are showing, the filepath and names are correct.

 

$doc Variable:

$doc = $_SERVER['DOCUMENT_ROOT']."social/users/".$u."/uploads/";

 

Upload Code:

<form action="" method="POST" enctype="multipart/form-data"> 
						<input name="new_image" type="file" class="input" /> 
						<input name="imgsubmit" type="submit" class="buttons" value="Upload" />
				</form> 
				<?php 

						$newdir = $dir."/uploads/";

						if(!empty($_POST['imgsubmit'])){ 
						  if (isset ($_FILES['new_image'])){ 
							  $imagename = $_FILES['new_image']['name']; 
							  $source = $_FILES['new_image']['tmp_name']; 
							  $target = $doc; 
							  move_uploaded_file($source, $target); 
				  
							  $imagepath = $imagename; 
							  $save = $doc.$imagepath; //This is the new file you saving 
							  $file = $doc.$imagepath; //This is the original file 
				  
							  list($width, $height) = getimagesize($file) ;  
				  
							  $modwidth = 500;  
				  
							  $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='".$newdir.$imagepath."'><br>";
				  
						  } 
						} 
				?>

Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/
Share on other sites

Sorry forgot to post those lol

Here they are:

 

Warning: move_uploaded_file(/home/sites/janedealsart.co.uk/public_html/social/users/Dr4g0nhe4rt/uploads) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 76

 

 

 

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpU6IZwg' to '/home/sites/janedealsart.co.uk/public_html/social/users/Dr4g0nhe4rt/uploads' in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 76

 

 

 

 

Warning: getimagesize(/home/sites/janedealsart.co.uk/public_html/social/users/Dr4g0nhe4rt/uploadsGuildWars2-Guardian-GW2.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 82

 

 

 

 

Warning: Division by zero in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 88

 

 

 

 

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 89

 

 

 

 

Warning: imagecreatefromjpeg(/home/sites/janedealsart.co.uk/public_html/social/users/Dr4g0nhe4rt/uploadsGuildWars2-Guardian-GW2.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 90

 

 

 

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 91

 

 

 

 

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/sites/janedealsart.co.uk/public_html/social/gd.php on line 93

Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392233
Share on other sites

Okay so i did what you said and it works, but now I have a slightly new problem.

 

Here is the uploading code:

<?php 

					$newdir = $dir."/uploads/";

					if(!empty($_POST['imgsubmit'])){ 
						if (isset ($_FILES['new_image'])){ 
							$imagename = $_FILES['new_image']['name'];
							$parts = explode( '.', $imagename );
							$extension = strtolower( $parts['1'] );
							$new_filename = uniqid().".".$extension;
							$source = $_FILES['new_image']['tmp_name']; 
							$target = $doc.$new_filename; 
							move_uploaded_file($source, $target); 

							$imagepath = $new_filename; 
							$save = $doc.$imagepath; //This is the new file you saving 
							$file = $doc.$imagepath; //This is the original file 

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

							$modwidth = 166;  

							$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) ;

							if(!empty($imagepath)){

								$imageavi = $dir2.$imagepath;

								$changeavi = update("users", "avatar = '$imageavi'", "username = '$u'") or die(mysql_error());
								if($changeavi){
									echo "Avatar Changed!";
								}
							}

						} 
					} 
				?>

 

The new problem I have is on the profile page:

$getbg = select("*", "users", "username = '$u'");
$bg = mysql_fetch_assoc($getbg);
$pic = $bg["background"];
$propicmargin = $bg["avatar"];
if($propicmargin){
list($width, $height) = getimagesize($propicmargin);

/*//Calculates Height of images that have an exact width of the box.
if($width == 166){
$margin = 166-$height;
$margin = $margin/2;
if($margin < 0){ $margin = 0; }
}*/

//Calculates Width & Height of small images to find the margin left & top.
if($width < 166 && $height < 166){
$margin = 166-$height;
$margin = $margin/2;
if($margin <= 0){ $margin = 0; }
$marginw = 166-$width;
$marginw = $marginw/2;
if($marginw <= 0){ $marginw = 0; }
}

$avatar = '<img src="'.$propicmargin.'" />';

}else{
$avatar = '<img src="'.$GLOBALS["nav"].'images/avatar.png" />';
}

 

To see the actual problem I am having:

 

http://janedealsart.co.uk/social

 

User: Guest

Pass: Guest657

Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392264
Share on other sites

The values for $width and $height are determined by the image given by getimagesize("/path/image.jpg");

yeah, I know what defines them, I was asking what they actualy were for that image at the point in time that you are going to send them to the calculation for the margin

Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392315
Share on other sites

okay, so i decided to change the avatar on a completely new account, what i found is that 83px margin left and top is a set value, it does not appear to have anything to do with the calculations but something else :/

 

Sorry for this slight bother

Edited by White_Lily
Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392332
Share on other sites

The size of the image you see on the website is 166(width) by 132(height).

 

Im not sure how the website managed to figure out 83px margins since whne i figured it out paper i got 17px (margin-top)... (I used the same equations as the website is using.

again, I know what size the image is, I'm asking for the values that are in the $width and $height variables when you echo/var_dump/die them onto the screen to try and establish if it's a GiGo problem or not Edited by Muddy_Funster
Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392333
Share on other sites

okay, so i decided to change the avatar on a completely new account, what i found is that 83px margin left and top is a set value, it does not appear to have anything to do with the calculations but something else :/

 

Sorry for this slight bother

 

I know it has nothing to do with the php calculations, I've been trying to steer you in the right direction for a couple of posts now.

Link to comment
https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392350
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.