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";
$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'> </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();
}
}
?>
//---------------------------------------------------
// 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'> </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
