update pro pic error

Started on the old forum in August 2013 · view the original in the archive · old links redirect here

12 replies · 792 views · started 13 years ago · 1 min read

5 participants
thunderwap Developer · 169 posts #1

hello ppl..

i am facing problem in uploading pic in pro. i cant figure out the problem.i seen code but i cant find it.

error is imagejpeg() [function.imagejpeg]: Unable to open './avatars/2u.jpg' for writing: Permission denied in /home/mysite/public_html/mysite/genproc.php on line 2287

i tried to put chmod to 777 though it dont worked. it says permission denied so i tried to put chmod to 777 so wats wrong in this code?

else if($action=="upavat"){

addonline(getuid_sid($sid),"Uploading Avatar Image","");
    echo "<head>";
    echo "<title>Uploading Avatar Image</title>";
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
    echo "</head>";
    echo "<body>";
$size = $_FILES['attach']['size']/1024;

$origname = $_FILES['attach']['name'];

$res = false;

$ext = explode(".", strrev($origname));

switch(strtolower($ext[0])){

        case "gpj":

	$res = true;

	break;

	case "gepj":

	$res = true;

	break;

}

$tm = time();

$uploaddir = "./avatars";

if($size>512){

	echo "File is larger than 512KB";

	

}

else if ($res!=true){

									

	echo "File type not supported! Please attach only a JPG/JPEG.";

}

else{

	$name = getuid_sid($sid);

	$uploadfile = $name.".".$ext;

	$uppath=$uploaddir."/".$uploadfile;

	move_uploaded_file($_FILES['attach']['tmp_name'], $uppath);

	$filewa=$uppath;

	list($width, $height, $type, $attr) = getimagesize($filewa);

	$newname=$uploaddir."/".$name."u.jpg";

	$newheight = ($height*128)/$width;

	$newimg=imagecreatetruecolor(128, $newheight);

	$largeimg=imagecreatefromjpeg($filewa);

	imagecopyresampled($newimg, $largeimg, 0, 0, 0, 0, 128, $newheight, $width, $height);

	imagejpeg($newimg, $newname);

	imagedestroy($newimg);

	imagedestroy($largeimg);

	$file1=$name."u.jpg";

	unlink($filewa);

        $res1 = mysql_query("UPDATE ibwf_users SET avatar='./avatars/$file1' WHERE id='".$name."'");

}

if($res1){

	echo "Your file $origname was successfully uploaded and set to your profile!";

}

else {

	echo "File couldn't be processed! Check error messages and report to a moderator or admin if applicable.";

}

echo "<br/><br/><b>0 </b><a accesskey=\"0\" href=\"index.php?action=main\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
    echo "</p>";
    echo "</body>";
}

WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!

something else Fellow · 2,296 posts #3

It won't be a chmod problem as GD Library is unable to open - (which it means it only needs readable permission)

Next - does the file exists on the server?

if yes then is the folder in the correct directory?

Next try using: ../avatar/

instead of /avatar/

Still causing problems? you may need to change the current working directory eg:

$old = getcwd();
chdir('avatars');
//Do your uploading etc here:
chdir($old);
ozziemale31 Lead · 861 posts #4

re

thunderwap wrote: hello ppl..

i am facing problem in uploading pic in pro. i cant figure out the problem.i seen code but i cant find it.

error is imagejpeg() [function.imagejpeg]: Unable to open './avatars/2u.jpg' for writing: Permission denied in /home/mysite/public_html/mysite/genproc.php on line 2287

i tried to put chmod to 777 though it dont worked. it says permission denied so i tried to put chmod to 777 so wats wrong in this code?

else if($action=="upavat"){

addonline(getuid_sid($sid),"Uploading Avatar Image","");
    echo "<head>";
    echo "<title>Uploading Avatar Image</title>";
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
    echo "</head>";
    echo "<body>";
$size = $_FILES['attach']['size']/1024;

$origname = $_FILES['attach']['name'];

$res = false;

$ext = explode(".", strrev($origname));

switch(strtolower($ext[0])){

        case "gpj":

	$res = true;

	break;

	case "gepj":

	$res = true;

	break;

}

$tm = time();

$uploaddir = "./avatars";

if($size>512){

	echo "File is larger than 512KB";

	

}

else if ($res!=true){

									

	echo "File type not supported! Please attach only a JPG/JPEG.";

}



else{

	$name = getuid_sid($sid);

	$uploadfile = $name.".".$ext;

	$uppath=$uploaddir."/".$uploadfile;

	move_uploaded_file($_FILES['attach']['tmp_name'], $uppath);

	$filewa=$uppath;

	list($width, $height, $type, $attr) = getimagesize($filewa);

	$newname=$uploaddir."/".$name."u.jpg";

	$newheight = ($height*128)/$width;

	$newimg=imagecreatetruecolor(128, $newheight);

	$largeimg=imagecreatefromjpeg($filewa);

	imagecopyresampled($newimg, $largeimg, 0, 0, 0, 0, 128, $newheight, $width, $height);

	imagejpeg($newimg, $newname);

	imagedestroy($newimg);

	imagedestroy($largeimg);

	$file1=$name."u.jpg";

	unlink($filewa);

        $res1 = mysql_query("UPDATE ibwf_users SET avatar='./avatars/$file1' WHERE id='".$name."'");

}

if($res1){

	echo "Your file $origname was successfully uploaded and set to your profile!";

}

else {

	echo "File couldn't be processed! Check error messages and report to a moderator or admin if applicable.";

}



echo "<br/><br/><b>0 </b><a accesskey=\"0\" href=\"index.php?action=main\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
    echo "</p>";
    echo "</body>";
}

i can already see your problem change $uploaddir = "avatars"; if your script is in your root folder of the site u dont need ../ ./ etc this is why u face your problem.

External image (may be gone) External image (may be gone)

External image (may be gone)

*****

**Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer.. Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free ***

thunderwap Developer · 169 posts #6

i am not using site in root directory. i am using in subdomain.

i tried to change $uploaddir = "./avatars"; into $uploaddir = "../avatars";

this worked and says profile successfully uploaded and set to the profile but it does not exists in folder when i see. so it does not displays in profile too.

WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!

ozziemale31 Lead · 861 posts #7

thunderwap wrote: i am not using site in root directory. i am using in subdomain.

i tried to change $uploaddir = "./avatars"; into $uploaddir = "../avatars";

this worked and says profile successfully uploaded and set to the profile but it does not exists in folder when i see. so it does not displays in profile too.

../ refers to a setup like this the sub folders are sim like so so if your script is in the web folder we use ../avatars avatars ecards smilies images mms share web wap


Now here is different we dont need to refer to ../ we just use avatars

avatars ecards smilies images mms share 404.htm 500.htm 403.htm indx.php config.php avatars.php avupload.php

$name = getuid_sid($sid);

$size = $_FILES['attach']['size']/1024;

$origname = $_FILES['attach']['name'];

$res = false;

$ext = explode(".", strrev($origname));

switch(strtolower($ext[0])){

        case "gpj":

	$res = true;

	break;
     case "gnp":

	$res = true;

	break;
    case "png":

	$res = true;

	break;
    case "fig":

	$res = true;

	break;
    case "gif":

	$res = true;

	break;

	case "gepj":

	$res = true;

	break;

}

$tm = time();

$uploaddir = "avatars";

if($size>512){
      echo "<div class=\"error\"><img src=\"images/no.jpg\" alt=\"-\"/>";
                echo "<big><strong>File Is Bigger the 512Kb</strong></big><br/>";
                echo "</div><br />";
}

else if ($res!=true){
       echo "<div class=\"error\"><img src=\"images/no.jpg\" alt=\"-\"/>";
                echo "<big><strong>File Type Isnt Supported</strong></big><br/>";
                echo "</div><br />";
	echo "File type not supported! Please attach only a JPG/JPEG.<br />";

}

else{

	$name = getuid_sid($sid);

	$uploadfile = $name.".".$ext;

	$uppath=$uploaddir."/".$uploadfile;

	move_uploaded_file($_FILES['attach']['tmp_name'], $uppath);

	$filewa=$uppath;

	list($width, $height, $type, $attr) = getimagesize($filewa);

	$newname=$uploaddir."/".$name."u.jpg";

	$newheight = ($height*128)/$width;

	$newimg=imagecreatetruecolor(128, $newheight);

	$largeimg=imagecreatefromjpeg($filewa);

	imagecopyresampled($newimg, $largeimg, 0, 0, 0, 0, 128, $newheight, $width, $height);

	imagejpeg($newimg, $newname);

	imagedestroy($newimg);

	imagedestroy($largeimg);

	$file1=$name."u.jpg";

	unlink($filewa);

        $res1 = mysql_query("UPDATE ibwf_users SET avatar='avatars/$file1' WHERE id='".$name."'");
       //$res1 = mysql_query("UPDATE ibwf_users SET avatar='avatars/$file1' WHERE id='".$name."'");// see your error why it doesnt get showen in the dbase?
      //$res1 = mysql_query("UPDATE ibwf_users SET avatar='$uploaddir/$file1' WHERE id='".$name."'"); // or we can use the default folder name already stated
}

if($res1){
           echo "<div class=\"done\"><img src=\"images/ok.gif\" alt=\"-\"/>";
                echo "<big><strong>$origname Was Successfully Added</strong></big><br/>";
       echo "</div><br />";
	echo "Your file $origname was successfully uploaded and set to your profile!";

}

else {
        echo "<div class=\"error\"><img src=\"images/no.jpg\" alt=\"-\"/>";
                echo "<big><strong>File Wasnt Processed</strong></big><br/>";
                echo "</div><br />";
	echo "File couldn't be processed! Check error messages and report to a moderator or admin if applicable.";

}

External image (may be gone) External image (may be gone)

External image (may be gone)

*****

**Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer.. Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free ***

ozziemale31 Lead · 861 posts #8

thunderwap wrote: i am not using site in root directory. i am using in subdomain.

i tried to change $uploaddir = "./avatars"; into $uploaddir = "../avatars";

this worked and says profile successfully uploaded and set to the profile but it does not exists in folder when i see. so it does not displays in profile too.

$uploaddir = "./avatars";try $uploaddir = "../../avatars"; as subdomain is a directory in main html folder an extra ../ allows u to navigate back one more folder

External image (may be gone) External image (may be gone)

External image (may be gone)

*****

**Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer.. Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free ***

thunderwap Developer · 169 posts #9

ozziemale31 wrote: $uploaddir = "./avatars";try $uploaddir = "../../avatars"; as subdomain is a directory in main html folder an extra ../ allows u to navigate back one more folder

i tried to put $uploaddir = "../../avatars"; and also $res1 = mysql_query("UPDATE ibwf_users SET avatar='../../avatars/$file1' WHERE id='".$name."'");

though it dont works. it given me errors in page and it was full with errors.

suppose my domain is test.com so my site is subdomain.test.com

i put avatars folder in subdomain. and i am not using web folder. index is in subdomain.

everything is alrtite but the pic we upload it do not goes into avatars folder. that file name which we upload do not exists in avatars folder and so no profile displays in profile.

WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!

something else Fellow · 2,296 posts #10

if the file is not uploading go back to chmod 755 via ftp if the file is still not uploading make sure you have a temp folder for the files to be uploaded to before they are moved to the correct directory.

Also would be good to know what those errors say - as we are all just guessing 🙂

thunderwap Developer · 169 posts #11

something else wrote: if the file is not uploading go back to chmod 755 via ftp if the file is still not uploading make sure you have a temp folder for the files to be uploaded to before they are moved to the correct directory.

Also would be good to know what those errors say - as we are all just guessing :)

tried to chmod into 755 though not working. i got tmp folder too. and i get errors when i put $uploaddir = "../../avatars";

Warning: move_uploaded_file(../../avatars/2.Array) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/mydomain/public_html/mysubdomain/genproc.php on line 2271

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpiGH1RB' to '../../avatars/2.Array' in /home/mydomain/public_html/mysubdomain/genproc.php on line 2271

Warning: getimagesize(../../avatars/2.Array) [function.getimagesize]: failed to open stream: No such file or directory in /home/mydomain/public_html/mysubdomain/genproc.php on line 2275

Warning: Division by zero in /home/mydomain/public_html/mysubdomain/genproc.php on line 2279

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/mydomain/public_html/mysubdomain/genproc.php on line 2281

Warning: imagecreatefromjpeg(../../avatars/2.Array) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/mydomain/public_html/mysubdomain/genproc.php on line 2283

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/mydomain/public_html/mysubdomain/genproc.php on line 2285

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/mydomain/public_html/mysubdomain/genproc.php on line 2287

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/mydomain/public_html/mysubdomain/genproc.php on line 2289

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/mydomain/public_html/mysubdomain/genproc.php on line 2291

Warning: unlink(../../avatars/2.Array) [function.unlink]: No such file or directory in /home/mydomain/public_html/mysubdomain/genproc.php on line 2295
 Your file scvaga.jpg was successfully uploaded and set to your profile!
 

Added after 33 minutes:

seems like it works sometimes and sometimes dont. but now it is working now. lets see how far it goes.

thanks guys.

WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!

ozziemale31 Lead · 861 posts #12

or we can do this $uploaddir = "../../avatars"; changeto $uploaddir = "http://test.com/avatars";

in the sql statement use $uploaddir/$file1/ the only other solution is prob moving the uploading script into the subdomain and link to it from there

External image (may be gone) External image (may be gone)

External image (may be gone)

*****

**Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer.. Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free ***

something else Fellow · 2,296 posts #13

you need to set the correct array key on the variable $ext

eg:

$uploadfile = $name.".".$ext[(count($ext)-1)];

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close