White_Lily Posted November 14, 2012 Share Posted November 14, 2012 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/ Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 Before I look at the code, show the errors that are being triggered. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392231 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392233 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 (edited) failed to open stream: Is a directory <--should probably give it away I would think....You're pointing a function that is used to move files at a directory, not a file. Edited November 14, 2012 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392238 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 $target is the target directory yes? I was under the impression $source was the file name... Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392243 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 $target is the target file name (with directory). you need to specify the full path and name with extension that you want the file to become once it is moved. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392260 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392264 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 I assume your reffering to the image being out of possition? Oh....and case sensitive user names? really? Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392266 Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 If the "new problem" that you are referring to is the image being out of position, please start a new thread in the CSS section since it is now out of the original problem's scope. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392268 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 OK, your margin is being set as 83px auto 0 83px so somethings not calculating right. whats the actual values for $width and $height? Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392271 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 The values for $width and $height are determined by the image given by getimagesize("/path/image.jpg"); Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392293 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 AyKay47 why the css section? im using PHP to determine the position of the image since (believe it or not) everyone's avatars would be different sizes. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392294 Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 You still have failed to provide us with the actual problem that you are having. All we can do is assume that the issue is the picture position, in which case the problem is the "margin-top" and "margin-left" properties in the CSS. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392305 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392315 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392324 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 and AyKay47, its the php that calculates the numbers needed for the styles of the avatars, and since the problem is with the php calculations and not the css then this is therefore a php problem and stays here. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392325 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 (edited) 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 November 14, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392332 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 (edited) 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 November 14, 2012 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392333 Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270669-image-uploading/#findComment-1392350 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.