upload des fichier RAR et ZIP

smookdogg29

WRInaute discret
Bonjour tout le monde voilà un formulaire qui me casse la tête depuis des heures, si quelqu'un peut m'aider svp
Code:
<?php
include('config.php');

$UploadDirectory	= 'uploaded_images/';
$PSBDirectory       = 'uploaded_files/';
 

if (!@file_exists($UploadDirectory)) {
	//destination folder does not exist
	die("Make sure Upload directory exist!");
}

if($_POST)
{	
	
		if(!isset($_POST['category']) || strlen($_POST['category'])<1)
	{
		//required variables are empty
		die("Please select a category.");
	}
	
	if(!isset($_POST['mName']) || strlen($_POST['mName'])<1)
	{
		//required variables are empty
		die("Please add a title.");
	}
	
	if(!isset($_POST['aName']) || strlen($_POST['aName'])<1)
	{
		//required variables are empty
		die("Please tell us author of the file.");
	}
	
	if(!isset($_POST['nSet']) || strlen($_POST['nSet'])<1)
	{
		//required variables are empty
		die("Please tell us how many items in the list.");
	}
	
		if(!isset($_POST['description']) || strlen($_POST['description'])<1)
	{
		//required variables are empty
		die("Please add a small description.");
	}
		
		if(!isset($_POST['license']) || strlen($_POST['license'])<1)
	{
		//required variables are empty
		die("Please select a license.");
	}
	
	if(!isset($_FILES['mFile']))
	{
		//required variables are empty
		die("Please add a image");
	}
	
	if(!isset($_FILES['zFile']))
	{
		//required variables are empty
		die("Please add file in zip format");
	}
	
	if(!isset($_POST['Tags']) || strlen($_POST['Tags'])<1)
	{
		//required variables are empty
		die("Please enter few tags.");
	}
	
	if($_FILES['mFile']['error'])
	{
		//File upload error encountered
		die(upload_errors($_FILES['mFile']['error']));
	}

	$FileName			= strtolower($_FILES['mFile']['name']); //uploaded file name
	$FileTitle			= $mysqli->escape_string($_POST['mName']); // file title
	$ImageExt			= substr($FileName, strrpos($FileName, '.')); //file extension
	$active             = 0;//File active
	$FileType			= $_FILES['mFile']['type']; //file type
	$FileSize			= $_FILES['mFile']["size"]; //file size
	$RandNumber   		= rand(0, 9999999999); //Random number to make each filename unique.
	$uploaded_date		= date("c",time());
	
	$Author  			= $mysqli->escape_string($_POST['aName']); // file author
	$Website  			= $mysqli->escape_string($_POST['aURL']); // Website
	$ItemSet            = $mysqli->escape_string($_POST['nSet']); // number in the set
	$Description        = $mysqli->escape_string($_POST['description']); // description
	$Category           = $mysqli->escape_string($_POST['category']); // description
	$License            = $mysqli->escape_string($_POST['license']); // license
	$Tags				= $mysqli->escape_string($_POST['Tags']); // tags
	
	//Zip File
	$PSBName			= strtolower($_FILES['zFile']['name']);
	$ZipExt			    = substr($PSBName, strrpos($PSBName, '.'));
	$ZipType			= $_FILES['zFile']['type']; //file type
	$ZipSize			= $_FILES['zFile']["size"]; //file size
	
		switch(strtolower($ZipType))
	{
		//allowed file types
		case ".zip": $type = "application/zip"; 
			break;
		default:
			die('Unsupported Zip File!'); //output error
	}
	
	switch(strtolower($FileType))
	{
		//allowed file types
		case 'image/png': //png file
		case 'image/gif': //gif file 
		case 'image/jpeg': //jpeg file
		case 'image/bmp': //bmp file
			break;
		default:
			die('Unsupported Image File!'); //output error
	}

  
	//Image File Title will be used as new File name
	$NewFileName = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), strtolower($FileTitle));
	$NewFileName = $NewFileName.'_'.$RandNumber.$ImageExt;
	
	//Zip File Title will be used as new File name
	$NewZipName = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), strtolower($FileTitle));
	$NewZipName = $NewZipName.'_'.$RandNumber.$ZipExt;
	
	
   //Rename and save uploded image file to destination folder.
   if(move_uploaded_file($_FILES['mFile']["tmp_name"], $UploadDirectory . $NewFileName ))
   {
	
  //Rename and save uploded zip file to destination folder.
   if(move_uploaded_file($_FILES['zFile']["tmp_name"], $PSBDirectory . $NewZipName ))
   {
		
// Insert info into database table.. do w.e!
		$mysqli->query("INSERT INTO resource(img_title, file_title, zip_file, author, website, item_set, description, category, license, tags, uploaded_date, active) VALUES ('$NewFileName', '$FileTitle', '$NewZipName','$Author','$Website','$ItemSet','$Description','$Category','$License','$Tags','$uploaded_date','$active')");
		
		die('Thank you for your submission.');
		
   }
   }else{
   		die('There seems to be a problem. please try again.');
   } 
}

//function outputs upload error messages, http://www.php.net/manual/en/features.file-upload.errors.php#90522
function upload_errors($err_code) {
	switch ($err_code) { 
        case UPLOAD_ERR_INI_SIZE: 
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 
        case UPLOAD_ERR_FORM_SIZE: 
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
        case UPLOAD_ERR_PARTIAL: 
            return 'The uploaded file was only partially uploaded'; 
        case UPLOAD_ERR_NO_FILE: 
            return 'No file was uploaded'; 
        case UPLOAD_ERR_NO_TMP_DIR: 
            return 'Missing a temporary folder'; 
        case UPLOAD_ERR_CANT_WRITE: 
            return 'Failed to write file to disk'; 
        case UPLOAD_ERR_EXTENSION: 
            return 'File upload stopped by extension'; 
        default: 
            return 'Unknown upload error'; 
    } 
} 
?>
dès que je clique sur envoyer ça me donne l'erreur "Unsupported Zip File!"
 

Blount

WRInaute impliqué
Bah, tu n'as pas 50 solutions, ton erreur provient de ce code:
PHP:
<span class="syntaxdefault"><br />       switch</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">strtolower</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$ZipType</span><span class="syntaxkeyword">))<br /></span><span class="syntaxdefault">       </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">          </span><span class="syntaxcomment">//allowed file types<br /></span><span class="syntaxdefault">          case </span><span class="syntaxstring">".zip"</span><span class="syntaxkeyword">:</span><span class="syntaxdefault"> $type </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"application/zip"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">             break</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">          default</span><span class="syntaxkeyword">:<br /></span><span class="syntaxdefault">             die</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Unsupported Zip File!'</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">//output error<br /></span><span class="syntaxdefault">       </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>

Alors, regardes le contenu de $ZipType.
Tu remarqueras qu'il ne contient pas ".zip".

D'ailleurs, niveau sécurité, il n'est pas conseillé d'utilisé cette variable qui est fourni par le navigateur.
 

smookdogg29

WRInaute discret
Blount a dit:
Bah, tu n'as pas 50 solutions, ton erreur provient de ce code:
PHP:
<span class="syntaxdefault"><br />       switch</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">strtolower</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$ZipType</span><span class="syntaxkeyword">))<br /></span><span class="syntaxdefault">       </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">          </span><span class="syntaxcomment">//allowed file types<br /></span><span class="syntaxdefault">          case </span><span class="syntaxstring">".zip"</span><span class="syntaxkeyword">:</span><span class="syntaxdefault"> $type </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"application/zip"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">             break</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">          default</span><span class="syntaxkeyword">:<br /></span><span class="syntaxdefault">             die</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Unsupported Zip File!'</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">//output error<br /></span><span class="syntaxdefault">       </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>

Alors, regardes le contenu de $ZipType.
Tu remarqueras qu'il ne contient pas ".zip".

D'ailleurs, niveau sécurité, il n'est pas conseillé d'utilisé cette variable qui est fourni par le navigateur.
bonjour et merci pour votre réponse que me conseillez-vous de mettre à la place
merci
 

Discussions similaires

Haut