Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1775

PostPosted: Fri Jul 27, 2012 7:37 pm Reply with quote

I search a simple upload method for saving images/avatars (jpg, gif and png) with a function in RN. I have variables with the filename and the filepath but i don't get it realized. I play with an code-snippet from an old file and try it to run in a update function.

Code:
$id = '1';   

$postavatar = 'file.jpg';
$myfilepath = 'path/to/my/folder/';

function upload($id, $postavatar, $myfilepath) {
global $prefix, $db;
   if (stripos($_FILES['postavatar']['type'],'image')!==false) {
      $size = getimagesize($_FILES['postavatar']['tmp_name']);
      if($size[0]==120 && $size[1]==120) {                     
         $avatarfile = rand(1000,9999).$_FILES['postavatar']['name'];
         $avatarfile = $db->sql_escape_string($avatarfile);
         $query = $db->sql_query('UPDATE ' .$prefix . '_myusers SET '."avatar='$avatarfile'".' WHERE id = \'' . $id . '\'');
         if(!move_uploaded_file($_FILES['postavatar']['tmp_name'],$myfilepath.$avatarfile)) {
            echo "fail";
         } else {
            echo "done";
         }
      }
   }
}


...any ideas?
 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Fri Jul 27, 2012 10:20 pm Reply with quote

What exactly is the problem? Have you narrowed it down to anything? Have you tried var_dump() on $_FILES to see if the file name etc is there?

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
neralex







PostPosted: Sat Jul 28, 2012 4:39 pm Reply with quote

I have got it sorted! I must check if "isset($_FILES['postavatar'])" and assign to the variable $postavatar.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©