Upload pictures in a massive way

Moderator: Coursenligne

Upload pictures in a massive way

Postby barakiel_vm » Mon Oct 17, 2011 10:06 pm

hi, i'm looking for someone to give some ideas, I'm implementing chamilo 1.8.8.4 in a highschool education system, we have 26 schools over the state and more than 25000 students and teachers, officially all the systems in the school must use the school id picture so we are looking for a way to upload directly to the server the users pic's, I tried to do it by uploading the picture in the four sizes that chamilo creates when you do it by the profile editing option, directly to the user folder in main/uploads/user, and then adding to the database the name of the picture but it didn't work, it just make my default picture to look blur but never showed the picture that i uploaded. Does anyone already faced this situation?

Thanks a lot for your help!!!!
barakiel_vm
 
Posts: 4
Joined: Tue Mar 01, 2011 9:07 pm

Re: Upload pictures in a massive way

Postby ywarnier » Tue Nov 01, 2011 5:46 pm

Hi Barakiel,

You seem to be using the right technique. Instead of uploading them manually, why don't you write a little script that re-uses the picture upload feature of Chamilo? You could use the update_user_picture() method in main/inc/lib/usermanager.lib.php by doing a script like this:
Code: Select all
<?php
require_once 'main/inc/global.inc.php';
require_once 'main/inc/lib/usermanager.lib.php';
//get the list of pictures from a directory, where every picture's name is [userid].jpg
$list = scandir('/tmp/pictures/');
foreach ($list as $picfile) {
  $user_id = substr($picfile,0-4);
  $res = UserManager::update_user_picture($user_id,'','/tmp/'.$picfile);
  if (empty($res)) { echo "Upload of picture for user $user_id has failed\n"; }
}
?>


Seems quite OK to me if you have the pictures with the user_id of the student in Chamilo, but you probably have them with their school ID, so you should probably search for the right user ID in the chamilo_main.user database... I'll let you do that as an exercise ;-)

Have fun!
ywarnier
 
Posts: 983
Joined: Wed Dec 16, 2009 3:12 pm

Re: Upload pictures in a massive way

Postby barakiel_vm » Thu Nov 03, 2011 7:07 pm

thanks ywarnier, i used your idea, just a little bit modified, with a simple select of mysql i get the user_id of each of the students but it didn't work, here is the code, do you have any ideas os what could be wrong?

Code: Select all
<?php
require_once 'main/inc/global.inc.php';
require_once 'main/inc/lib/usermanager.lib.php';

$list = scandir('pcusr/');
$conexion = mysql_connect("server","user","psw");
   mysql_select_db("chamilo_main",$conexion);
foreach ($list as $picfile) {
   if($picfile!="."&&$picfile!="..")
   {
   
   $user_official= str_replace(".jpg","",strtolower($picfile));
   $user_official= intval($user_official); //i did this because my teachers pics are in 4 digits format, for example the teacher with employee id 20 has the user_id 20 in chamilo but the picture name is 0020.jpg
   $queEmp="SELECT user_id FROM user WHERE official_code ='".$user_official."'";
   $result=mysql_query($queEmp,$conexion) or die(mysql_error());
   $row=mysql_fetch_object($result);
   $user_id=$row->user_id;
   if(!empty($user_id)){$res = UserManager::update_user_picture($user_id,'','pcusr/'.$picfile);
     if (empty($res)) { echo "Upload of picture for user $user_id has failed<br />\n"; }else{echo $res;}}
   }
   
}
?>
barakiel_vm
 
Posts: 4
Joined: Tue Mar 01, 2011 9:07 pm

Re: Upload pictures in a massive way

Postby ywarnier » Thu Nov 03, 2011 8:41 pm

If the code was copy-pasted "as is", then you definitely want spaces around the "&&" in your condition on picfile :-)
Otherwise give me an error message or something to work on.
ywarnier
 
Posts: 983
Joined: Wed Dec 16, 2009 3:12 pm

Re: Upload pictures in a massive way

Postby lfreddecolo » Mon Feb 06, 2012 10:59 am

This is the third edit to the question, and I've now removed the original text as it's clearly no longer relevant.

I need to write a client that will allow users to upload massive files to the server. AJAX and Flash appear to be out as they insist on reading the files into memory before submitting them. I've been looking around at pre-built applets but nothing looks entirely promising.

Looking for advice on how to do this. The issue is both client and server side. PHP is probably not the best server side solution for gathering such files... for that matter does the server need to be 64bit to even address a file that's over 4gigs?

On the client, I'd prefer it be browser based, but am now thinking that maybe it's better to write it as a platform application (even though that's a lot more hassle).

Really, I'm open to anything, as long as it's relatively reliable.
lfreddecolo
 
Posts: 2
Joined: Mon Feb 06, 2012 10:25 am

Re: Upload pictures in a massive way

Postby ywarnier » Mon Feb 06, 2012 5:23 pm

Hi,

Please do not put commercial links in your posts unless they are totally relevant to what you are writing, which was not the case here.

I'm not sure about the 4GB file limit and 64bit, actually (that's a good question but we've never been faced with single files this large until now).

If you want to upload large files of the size you mention, then I would definitely recommend using a specific protocol for that. PHP supports both FTP ("File Transfer" Protocol) and SFTP (for a more secure version) but these would have to be implemented on the server, which requires a non-trivial amount of work if you do it from scratch and integrate it into Chamilo.
ywarnier
 
Posts: 983
Joined: Wed Dec 16, 2009 3:12 pm


Return to Development suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron

Upload pictures in a massive way

Moderator: Coursenligne

Upload pictures in a massive way

Postby barakiel_vm » Mon Oct 17, 2011 10:06 pm

hi, i'm looking for someone to give some ideas, I'm implementing chamilo 1.8.8.4 in a highschool education system, we have 26 schools over the state and more than 25000 students and teachers, officially all the systems in the school must use the school id picture so we are looking for a way to upload directly to the server the users pic's, I tried to do it by uploading the picture in the four sizes that chamilo creates when you do it by the profile editing option, directly to the user folder in main/uploads/user, and then adding to the database the name of the picture but it didn't work, it just make my default picture to look blur but never showed the picture that i uploaded. Does anyone already faced this situation?

Thanks a lot for your help!!!!
barakiel_vm
 
Posts: 4
Joined: Tue Mar 01, 2011 9:07 pm

Re: Upload pictures in a massive way

Postby ywarnier » Tue Nov 01, 2011 5:46 pm

Hi Barakiel,

You seem to be using the right technique. Instead of uploading them manually, why don't you write a little script that re-uses the picture upload feature of Chamilo? You could use the update_user_picture() method in main/inc/lib/usermanager.lib.php by doing a script like this:
Code: Select all
<?php
require_once 'main/inc/global.inc.php';
require_once 'main/inc/lib/usermanager.lib.php';
//get the list of pictures from a directory, where every picture's name is [userid].jpg
$list = scandir('/tmp/pictures/');
foreach ($list as $picfile) {
  $user_id = substr($picfile,0-4);
  $res = UserManager::update_user_picture($user_id,'','/tmp/'.$picfile);
  if (empty($res)) { echo "Upload of picture for user $user_id has failed\n"; }
}
?>


Seems quite OK to me if you have the pictures with the user_id of the student in Chamilo, but you probably have them with their school ID, so you should probably search for the right user ID in the chamilo_main.user database... I'll let you do that as an exercise ;-)

Have fun!
ywarnier
 
Posts: 983
Joined: Wed Dec 16, 2009 3:12 pm

Re: Upload pictures in a massive way

Postby barakiel_vm » Thu Nov 03, 2011 7:07 pm

thanks ywarnier, i used your idea, just a little bit modified, with a simple select of mysql i get the user_id of each of the students but it didn't work, here is the code, do you have any ideas os what could be wrong?

Code: Select all
<?php
require_once 'main/inc/global.inc.php';
require_once 'main/inc/lib/usermanager.lib.php';

$list = scandir('pcusr/');
$conexion = mysql_connect("server","user","psw");
   mysql_select_db("chamilo_main",$conexion);
foreach ($list as $picfile) {
   if($picfile!="."&&$picfile!="..")
   {
   
   $user_official= str_replace(".jpg","",strtolower($picfile));
   $user_official= intval($user_official); //i did this because my teachers pics are in 4 digits format, for example the teacher with employee id 20 has the user_id 20 in chamilo but the picture name is 0020.jpg
   $queEmp="SELECT user_id FROM user WHERE official_code ='".$user_official."'";
   $result=mysql_query($queEmp,$conexion) or die(mysql_error());
   $row=mysql_fetch_object($result);
   $user_id=$row->user_id;
   if(!empty($user_id)){$res = UserManager::update_user_picture($user_id,'','pcusr/'.$picfile);
     if (empty($res)) { echo "Upload of picture for user $user_id has failed<br />\n"; }else{echo $res;}}
   }
   
}
?>
barakiel_vm
 
Posts: 4
Joined: Tue Mar 01, 2011 9:07 pm

Re: Upload pictures in a massive way

Postby ywarnier » Thu Nov 03, 2011 8:41 pm

If the code was copy-pasted "as is", then you definitely want spaces around the "&&" in your condition on picfile :-)
Otherwise give me an error message or something to work on.
ywarnier
 
Posts: 983
Joined: Wed Dec 16, 2009 3:12 pm

Re: Upload pictures in a massive way

Postby lfreddecolo » Mon Feb 06, 2012 10:59 am

This is the third edit to the question, and I've now removed the original text as it's clearly no longer relevant.

I need to write a client that will allow users to upload massive files to the server. AJAX and Flash appear to be out as they insist on reading the files into memory before submitting them. I've been looking around at pre-built applets but nothing looks entirely promising.

Looking for advice on how to do this. The issue is both client and server side. PHP is probably not the best server side solution for gathering such files... for that matter does the server need to be 64bit to even address a file that's over 4gigs?

On the client, I'd prefer it be browser based, but am now thinking that maybe it's better to write it as a platform application (even though that's a lot more hassle).

Really, I'm open to anything, as long as it's relatively reliable.
lfreddecolo
 
Posts: 2
Joined: Mon Feb 06, 2012 10:25 am

Re: Upload pictures in a massive way

Postby ywarnier » Mon Feb 06, 2012 5:23 pm

Hi,

Please do not put commercial links in your posts unless they are totally relevant to what you are writing, which was not the case here.

I'm not sure about the 4GB file limit and 64bit, actually (that's a good question but we've never been faced with single files this large until now).

If you want to upload large files of the size you mention, then I would definitely recommend using a specific protocol for that. PHP supports both FTP ("File Transfer" Protocol) and SFTP (for a more secure version) but these would have to be implemented on the server, which requires a non-trivial amount of work if you do it from scratch and integrate it into Chamilo.
ywarnier
 
Posts: 983
Joined: Wed Dec 16, 2009 3:12 pm


Return to Development suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron

Social network

Youtube

Subscribe to our newsletter

Leave us your e-mail in the box below, then make sure you approve the confirmation e-mail you will receive

 


 

Upcoming events