Hello

I'm sorry to post here, but i didn't find help on the french forum :s

I'm playing with Drupal since 3 months, and i'm trying to build a carousel module using jquery, but I've got some probleme ton use the drupal uploading function.

First I've activated the upload module

Next I've fill the informations about the Files system path in Admin>Site config>File system to

tmp folder:
sites/default/tmp

Third I've build my field for my user in .module

function carousel_form(& $node){

...

  $form['#attributes'] = array('enctype' => "multipart/form-data");
	$form['picture_upload'] = array(
	'#type'=> 'file',
	'#title' => 'Image',
	'#size' => 50,
	'#description' => t("Select you imagel."),
	);
		
	$form['submit'] = array(
	'#type' => 'submit',
	'#value' => 'Upload'
	); 
}

and the function to upload :

function carousel_form_submit(&$form, &$form_state) {
	
	$validators=array();
  if ($file = file_save_upload('picture_upload', $validators)) {
  	  drupal_set_message($nom_fichier.' a été uploadé.');
    }
    else
    {
        drupal_set_message($nom_fichier."n'a pas été uploadé !");
    }
}

When i try to upload nothing appends :s
I've print the $_Files :
Array ( [files] => Array ( [name] => Array ( [picture_upload] => 03.jpg [upload] => ) [type] => Array ( [picture_upload] => image/jpeg [upload] => ) [tmp_name] => Array ( [picture_upload] => C:\Windows\Temp\php66F8.tmp [upload] => ) [error] => Array ( [picture_upload] => 0 [upload] => 4 ) [size] => Array ( [picture_upload] => 169794 [upload] => 0 ) ) )

Please could you help me ?

Best regards

Comments

budylove’s picture

up

Impossible to debug :s

arcaneadam’s picture

if($file = file_save_upload('picture_upload', $validators)) will always evaluate to true. because = is an assignment operator all it does is says if $file is assigned the value of file_save_upload() (regardless of weather or not that value is null or not) then evaluate as true.

Here is how it should look:

function carousel_form_submit(&$form, &$form_state) {

$validators=array();
$file = file_save_upload('picture_upload', $validators);
  if (!$file) {
           drupal_set_message($nom_fichier."n'a pas été uploadé !", 'error');
    }
    else
    {

 drupal_set_message($nom_fichier.' a été uploadé.');
    }
}


Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

budylove’s picture

Thanks you to answering me :)

I change my code with your, but nothing append.

None of my message appear, why ?

Any idea ?

arcaneadam’s picture

function carousel_form_submit(&$form, &$form_state) {
 drupal_set_message("Test Test Test Test", 'error');
$validators=array();
$file = file_save_upload('picture_upload', $validators);
  if (!$file) {
           drupal_set_message($nom_fichier."n'a pas été uploadé !", 'error');
    }
    else
    {

drupal_set_message($nom_fichier.' a été uploadé.');
    }
}

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

budylove’s picture

I can't see your message

drupal_set_message("Test Test Test Test", 'error');

arcaneadam’s picture

are you getting a a blank screen or is the message just not showing.?

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

budylove’s picture

It's just the messaga not showing

When i do a print_r($_FILES) I can see :

Array ( [files] => Array ( [name] => Array ( [picture_upload] => 05.jpg [upload] => ) [type] => Array ( [picture_upload] => image/jpeg [upload] => ) [tmp_name] => Array ( [picture_upload] => C:\Windows\Temp\phpB83F.tmp [upload] => ) [error] => Array ( [picture_upload] => 0 [upload] => 4 ) [size] => Array ( [picture_upload] => 27978 [upload] => 0 ) ) )

arcaneadam’s picture

Are you using a custom theme? Maybe the print $messages; is missing from it.

You need to check two things.

1. First check you files directory and see if the files are saving
2. Check your theme page.tpl.php and make sure it has print $messages; in it.

I see no reason why you wouldn't be able to see the set messages in this function.

Also if you can attach your entire piece of code I can test it on m sandbox site.

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

budylove’s picture

Hello

I'm not using a custom theme, just Garland. I can see error message when I try to create a node without name, so it work.

And when I tried to upload, none of the files are saving in my directory and nothing more in the file field database...

I have attached my source code, but be indulgent it's my first, so i'm sure I make a lot of mistake :)

I didn't create de .install yet so you have to create yourself the field in the database (You can find it in the file .install).

http://juliendubreuil.fr/files/jcarousel2.rar

Thx

budylove’s picture

An idea ?

arcaneadam’s picture

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

budylove’s picture

hello :)

Did you find some time to check my module ?

arcaneadam’s picture

your form function is not passing the correct form arguments

 function jcarousel2_form(& $node){
}

is how it reads now

 function jcarousel2_form($form_state, $node){
}

is how it should look.

This is how your submit function should probably look

function jcarousel2_form_submit($form, &$form_state) {
$validators=array();
$dest = 'Your/files/destination/directory';
$file = file_save_upload('picture_upload', $validators, $dest);
  if (!$file) {
   	 	drupal_set_message($nom_fichier."n'a pas été uploadé !", 'error');
   }else{
			drupal_set_message($nom_fichier.' a été uploadé.');
   }
}

I am going to look at it a bit more because I'm pretty sure you will need to set the file status with file_set_status.

also you need to define the variable $nom_ficheir somewhere in your submit function.

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

budylove’s picture

Thanks, I didn't find yet.

I'm still working on :s