Aide - Recherche - Membres - Calendrier
Version complète : [php] Probleme Script D'upload De Fichier
La Communauté TitaXium > Service Communication > Espace Developpement
Spiky
Bonjour à tous, j'ai récemment installer une MOD sur mon forum (IPB). Il s'agit de la MOD IBStore 3.0,
dans cette MOD, il y a un script d'upload mais le problème c'est que j'upload un fichier, il me le mets dans un sous-dossier inexistant (celui de l'ID de ma session).

Voici l'erreur en question:
Citation (Erreur)
Warning: filesize(): Stat failed for ./sources/store/downloads/eb9a953aabbfd36fa5117a97acc13b89 (errno=2 - No such file or directory) in /home/httpd/vhosts/gfx-dimension.com/httpdocs/forum/sources/storeitems/ownchange/item_paytodownload.php on line 157


Je pense que c'est cette parcelle de code qui bug:

Code
unlink($upload_full);
               $IN['ibsettings_realname'] = $noext_filename.'.'.$uploaded_ext;
               $IN['ibsettingstype_realname'] = "string";
               $IN['ibsettings_mimetype'] = $mimetype;
               $IN['ibsettingstype_mimetype'] = "string";
               $IN['ibsettings_fakename'] = $filename;
               $IN['ibsettingstype_fakename'] = "string";
               $IN['ibsettings_filesize'] = filesize($new_file);
               $IN['ibsettingstype_filesize'] = "int";


Je pense que tout le code source vous sera utile:

Code
<?
//---------------------------------------------------
// IBStore Pay to Download
//---------------------------------------------------
class item_paytodownload extends template {
       var $name = "File Download";
       var $desc = "Download the selected file.";
       var $loadlang = 1;
                                                                                                               
       function on_add() {
               global $SKIN;
               if($this->extra == "edit") {
                       $admin .= $SKIN->add_td_basic("Leave blank to keep the current file.");  
               }
               $admin .= $SKIN->add_td_row(array("<b>File:</b><br>File that is downloaded when this is used.<br /><b>Folders:</b> You will need to zip/rar/tar/gzip a folder to allow users to download them." ,
                                                                 $SKIN->form_upload("FILE")
                                        )      );

               $admin .= $SKIN->add_td_row(array("<b>Compression:</b><br>Compression to use on the file." ,
                                                                 $SKIN->form_dropdown("compression",array(0 => array(0,'None'),
                                                                                                                                                                         1 => array('gzip','gzipped (.gz)'),
                                                                                                                                                                         2 => array('bzip','bzipped (.bz2)')))
                                        )      );
               if($this->test_exec() == TRUE) {
                       $admin .= $SKIN->add_td_row(array("<b>Attempted Compression:</b><br>File is compressed using PHP and exec and shell_exec." ,
                                                                         $SKIN->form_dropdown("compression_try",array( 0 => array(0,'None'),
                                                                                                                                                                       1 => array('zip','zip (.zip)'),
                                                                                                                                                                       2 => array('tgz','gzipped tar (.tgz)'),
                                                                                                                                                                       3 => array('tar','tar (.tar)'),))
                                                )      );
               } else {
                       $admin .= $SKIN->add_td_basic("Sorry, shell_exec and exec are disabled, you cannot access compression types like zip,tgz and tar.");                    
               }
               return $admin;
       }
       function test_exec() {
               if(SAFE_MODE_ON == 1) return FALSE;
               @exec("ls",$output,$value);
               if($value == 0) {
                       $this->exectype = "exec";
                       return TRUE;
               } else if(@shell_exec("ls  2>&1") != "") {
                       $this->exectype = "shell";
                       return TRUE;
               }
               return FALSE;
       }
       function shellexec($command) {
               if(SHELL_EXEC == FALSE) return 0;
               $success = 0;
               if($this->exectype == "exec") {
                       exec($command,$output,$value);
                       if($value == 0) $success = 1;
               } else if($this->exectype == "shell") {
                       if(shell_exec($command." 2>&1") != "") {
                               $success = 0;
                       }
               }
               return $success;
       }
       // I am amazed this worked. O_o
       function on_add_run() {
               global $IN,$INFO;
               $FILE = $_FILES['FILE'];
               if($FILE['name'] == "" || !$FILE['name'] || $FILE['name'] == "none") return;
               
               define("SHELL_EXEC",$this->test_exec());
               $compression_mime = array(      'tar' => "application/x-tar",
                                                                       'zip' => "application/x-zip-compressed",
                                                                       'tgz' => "application/x-compressed",
                                                                       'gz' => "application/x-gzip",
                                                                       'bz2' => "application/x-bzip",);

               $FILE_NAME            = $FILE['name'];
               $temp_name           = $FILE['tmp_name']; // From
               $filename             = md5(microtime()); // Stored as
               $uploadpath     = ROOT_PATH."sources/store/downloads"; // Upload Path
               $new_file             = $uploadpath."/".$filename; // New file name
               $upload_full    = $uploadpath."/".$FILE_NAME; // New file name with uploaded name
               $mimetype             = preg_replace("/^(.+?);.*$/","\\1",$FILE['type']); // Starting mime type
               $uploaded_ext   = $this->_getext($FILE_NAME);
               $noext_filename = str_replace(".".$uploaded_ext,"",$FILE_NAME);
               $file_ext              = "ibf";
               

               if(!@chmod($uploadpath,0777)) $this->shellexec("chmod 0777 $uploadpath");
               
               if(!move_uploaded_file($temp_name,$upload_full)) {
                       $this->_error("Sorry, we could not upload {$FILE_NAME} to ./sources/store/downloads/.
                                                       <br />Please check that the folder exists and that ./sources/store/downloads is chmoded to 0777.");
               }
               
               if($IN['compression_try'] == "zip") {
                       if($this->shellexec("zip $new_file $upload_full") == 1) {
                               $file_ext = "zip";
                               $uploaded_ext = "zip";
                               $mimetype = $compression_mime[$file_ext];
                               // Not sure how this works O_O
                               rename($new_file.'.zip',str_replace(".zip","",$new_file));
                               $IN['compression'] = "";
                       }
               } else if($IN['compression_try'] == "tgz") {
                       $oldpath = getcwd();
                       @chdir($uploadpath);
                       if($this->shellexec("tar cfz $filename $FILE_NAME") == 1) {
                               $file_ext = "tgz";
                               $uploaded_ext = "tgz";
                               $mimetype = $compression_mime[$file_ext];
                               $IN['compression'] = "";
                       }                    
                       @chdir($oldpath);
               } else if($IN['compression_try'] == "tar") {
                       $oldpath = getcwd();
                       @chdir($uploadpath);
                       if($this->shellexec("tar cf $filename $FILE_NAME") == 1) {
                               $file_ext = "tar";
                               $uploaded_ext = "tar";
                               $mimetype = $compression_mime[$file_ext];
                               $IN['compression'] = "";
                       }                    
                       @chdir($oldpath);
               }
               if($IN['compression'] == "gzip") {
                       $fp = fopen($upload_full,"r");
                       $contents = fread($fp,filesize($upload_full));
                       $dump_buffer = gzencode($contents);
                       fclose($fp);        
                       $contents = $dump_buffer.$contents;
                       touch($new_file);
                       $fp = fopen($new_file,"a+");
                       fwrite($fp,$contents,strlen($contents));
                       fclose($fp);
                       $file_ext = "gz";                    
                       $mimetype = $compression_mime[$file_ext];
                       $uploaded_ext = $uploaded_ext.".".$file_ext;
               } else if($IN['compression'] == "bzip") {
                       $fp = fopen($upload_full,"r");
                       $contents = fread($fp,filesize($upload_full));
                       $dump_buffer = bzcompress($contents);
                       fclose($fp);        
                       $contents = $dump_buffer.$contents;
                       touch($new_file);
                       $fp = fopen($new_file,"a+");
                       fwrite($fp,$contents,strlen($contents));
                       fclose($fp);
                       $file_ext = "bz2";                  
                       $mimetype = $compression_mime[$file_ext];
                       $uploaded_ext = $uploaded_ext.".".$file_ext;
               }
               unlink($upload_full);
               $IN['ibsettings_realname'] = $noext_filename.'.'.$uploaded_ext;
               $IN['ibsettingstype_realname'] = "string";
               $IN['ibsettings_mimetype'] = $mimetype;
               $IN['ibsettingstype_mimetype'] = "string";
               $IN['ibsettings_fakename'] = $filename;
               $IN['ibsettingstype_fakename'] = "string";
               $IN['ibsettings_filesize'] = filesize($new_file);
               $IN['ibsettingstype_filesize'] = "int";
       }
       function on_use() {
               global $ibforums,$DB;
               return <<<EOF
                         <tr>
                               <td class='pformstrip' width='100%' colspan='3'>{$this->lang['download']}</td>
                       </tr>
                         <tr>
                               <td class='row2' width='50%' colspan='3'><b> <a href="{$ibforums->base_url}act=store&CODE=do_useitem&itemid={$this->item['id']}"> {$this->lang['start_download']} </a>, {$this->lang['download_deleted']}</b></td>
                        </tr>
                         <tr>
                               <td class='pformstrip' colspan='3'>&nbsp;</td>
                          </tr>
                       </form>
EOF;
       }
       function do_on_use() {
               global $ibforums,$DB;
               $this->_deleteitem();
               header("Content-Disposition: attachment; filename={$this->settings['realname']}");
               header("Content-Type: {$this->settings['mimetype']}");
               header("Content-Length: {$this->settings['filesize']}");
               header("Pragma: no-cache");
               $fp = fopen(ROOT_PATH."sources/store/downloads/".$this->settings['fakename'],"rb");
               fpassthru($fp);
               fclose($fp);
               flush();
               exit();  
       }
}
?>


Merci de votre aide.
Spiky smile.gif
Spiky
Personne? sad.gif
Eltasia
Un peu de patience svp!

Veillez attendre un minimum de 48 heures avant de poster, merci! wink.gif
Spiky
48h c'est un petit peu excessif il me semble... smile.gif Même sur des communauté plus grosses que celle-ci 12h suffisent smile.gif
La_fouine
Bonjour,

Tu devrais plutot essayé sur ce forum ci : http://forums.invisionboard.fr/index.php

Titaxium n'est pas un forum de support pour les mods invision, donc tu aura surement moins de réponse que si tu va sur un forum spécialisé smile.gif
Spiky
Je le sais pertinemment, mais TitaXium possède un forum d'aide en programmation, et je pense que la source que j'ai postée est en PHP wink.gif

Merci pour le lien smile.gif
tyx
Citation (Spiky @ dimanche 16 avril 2006 à 13h34)
48h c'est un petit peu excessif il me semble... smile.gif Même sur des communauté plus grosses que celle-ci 12h suffisent smile.gif
*



Alors faut aller là bas : >

Toujours est-til que c'est un problème de chemin et que le script n'est pas complet pour permettre un debuguage, vu que je ne vois nulle part la définition de la contante ROOT_PATH
Fantome
C'est une définition internet a IPB. Donc il faudrais avoir le code entier d'ipb.
Le sujet étant maintenant ouvert sur invisionboard.fr, je pense que celui est devenue inutile.
Ouark
Juste au passage, en ce qui concerne l'aide des mods IPb => IPBR-FR
Fantome
@Ouark : non c'est La_fouine qui a raison il faut aller sur http://forums.invisionboard.fr ipbr-fr n'existe plus, les deux site (IPBR-Fr et IBF) ont fusionné.
Ceci est une version "bas débit" de notre forum. Pour voir la version complète avec plus d'informations, la mise en page et les images, veuillez cliquer ici.
Invision Power Board © 2001-2010 Invision Power Services, Inc.