7 Replies - 2108 Views - Last Post: 08 August 2009 - 03:10 PM Rate Topic: -----

#1 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 513
  • Joined: 21-December 08

Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 03:23 AM

I have this site http://freecode.ueuo.com. On my localhost it works to upload files but it does not when i try to do it on the url above specified. It gives me the error that 'the file is not a rar archive' altough it is.
How can i resolve this problem?
Is This A Good Question/Topic? 0
  • +

Replies To: Cannot upload rar files when site uploaded on server

#2 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 03:34 AM

What does your code look like? :) Is it a custom error you've written yourself or is it a server error? It could be a limitation on the server you are hosted on, file-size, mime-type, etc...


View Postlivium, on 8 Aug, 2009 - 12:23 PM, said:

I have this site http://freecode.ueuo.com. On my localhost it works to upload files but it does not when i try to do it on the url above specified. It gives me the error that 'the file is not a rar archive' altough it is.
How can i resolve this problem?

Was This Post Helpful? 0
  • +
  • -

#3 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 513
  • Joined: 21-December 08

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 03:42 AM

It is a error which is defined by me.

So, it is not a limitation by the server.


OHHHHHH, wait a minute. Now i have this error on my localhost too. But i didn't have it previously. Dam it.
I will try to see why it doesn't work on localhost first.
Sorry for this error.

This post has been edited by livium: 08 August 2009 - 03:47 AM

Was This Post Helpful? 0
  • +
  • -

#4 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 03:45 AM

ok, if you want help you have to show your code! If you are certain that the error does not adhere from your code you should contact your host and ask if there are any limitations whatsoever stating what you can and can not upload with PHP onto the server! :)
Was This Post Helpful? 0
  • +
  • -

#5 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 513
  • Joined: 21-December 08

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 04:08 AM

<?php
//session_start();
$username="";
if (isset($_SESSION['user'])) $username=$_SESSION['user'];
else {
$_SESSION['goto_upload']=1;
header("location:signin.php?from_upload=1");
}

$director="user_data"."/".$username."/";
if (!is_dir($director)) mkdir($director) or die ("Error mkdir");



$file_error=0;
$picture_error=0;


if ($_FILES["file"]["error"] > 0) $file_error=1;
  else
	if ($_FILES["file"]["size"]>10485760 )  $file_error=2;
else
   if ($_FILES["file"]["type"] !="application/x-rar-compressed") $file_error=3;
	 else
	 {
	 $_FILES["file"]["name"]=str_replace(".rar","_".$username.".rar",$_FILES["file"]["name"]);
	 
	 if (file_exists($director . $_FILES["file"]["name"]))   $file_error=4;
	 }
 
if ($_FILES["file_picture"]["name"] !="") {
	$picture=1;
 if ($_FILES["file_picture"]["error"] > 0)  $picture_error=1;
  else
	  if ($_FILES["file_picture"]["size"]>1048576 )$picture_error=2;
	else
		 if ($_FILES["file_picture"]["type"] !="image/jpeg") $picture_error=3;
}
else  $picture=0;
  
$string_file_error1="An error has occured on loading file: " . $_FILES["file"]["error"]."." . "\n";
$string_file_error2='File size must be less than 10 MB ! \n';
$string_file_error3="This file is not a rar archive! \n";
$string_file_error4="This file was already uploaded! Please upload another file.\n";

$string_picture_error1="An error has occured on loading picture: " . $_FILES["file_picture"]["error"] .".". "\n";
$string_picture_error2="Picture size must be less than 1 MB !\n";
$string_picture_error3="The picture is not a jpeg ! \n";

$mesaj="";

if ($file_error==0 && $picture_error==0)
{
	move_uploaded_file($_FILES["file"]["tmp_name"], $director.$_FILES["file"]["name"]);
	$_FILES["file_picture"]["name"]=str_replace(".rar","_pict.jpg",$_FILES["file"]["name"]); //asta nu stiu ce face
	move_uploaded_file($_FILES["file_picture"]["tmp_name"], $director.$_FILES["file_picture"]["name"]);
										 
		$mesaj="					Upload succesfull !";
		$mesaj=str_replace(array("\n", "\r"), "  ", $mesaj);			  
		 }


else if ($file_error==0 && $picture_error==1)  $mesaj=$string_picture_error1;
else if  ($file_error==0 && $picture_error==2) $mesaj=$string_picture_error2;
else if  ($file_error==0 && $picture_error==3) $mesaj=$string_picture_error3;

else if ($file_error==1 && $picture_error==0)  $mesaj=$string_file_error1;
else if ($file_error==1 && $picture_error==1)  $mesaj=$string_file_error1.$string_picture_error1;
else if  ($file_error==1 && $picture_error==2) $mesaj=$string_file_error1.$string_picture_error2;
else if  ($file_error==1 && $picture_error==3) $mesaj=$string_file_error1.$string_picture_error3;

else if ($file_error==2 && $picture_error==0)  $mesaj=$string_file_error2;
else if  ($file_error==2 && $picture_error==1) $mesaj=$string_file_error2.$string_picture_error1;
else if ($file_error==2 && $picture_error==2)  $mesaj=$string_file_error2.$string_picture_error2;
else if ($file_error==2 && $picture_error==3)  $mesaj=$string_file_error2.$string_picture_error3;

else if  ($file_error==3 && $picture_error==0) $mesaj=$string_file_error3;
else if ($file_error==3 && $picture_error==1)  $mesaj=$string_file_error3.$string_picture_error1;
else if  ($file_error==3 && $picture_error==2) $mesaj=$string_file_error3.$string_picture_error2;
else if  ($file_error==3 && $picture_error==3) $mesaj=$string_file_error3.$string_picture_error3;

else if  ($file_error==4 && $picture_error==0) $mesaj=$string_file_error4;
else if ($file_error==4 && $picture_error==1)  $mesaj=$string_file_error4.$string_picture_error1;
else if  ($file_error==4 && $picture_error==2) $mesaj=$string_file_error4.$string_picture_error2;
else if  ($file_error==4 && $picture_error==3) $mesaj=$string_file_error4.$string_picture_error3;
else 
$mesaj="Upload could not be performed !";
$mesaj=str_replace(array("\n", "\r"), "  ", $mesaj);



if (trim($mesaj)=="Upload succesfull !") //inserare in baza de date
{

$code=$_POST['code'];
$lang=$_POST['lang'];



$descriere_text=trim($_POST['descriere']);
if ($descriere_text!="") $descriere=1; else $descriere=0;

$server='localhost';
$db='free_code';
$admin='root';


include_once("functions.php");
$file_name=str_replace(".rar","",$_FILES['file']['name']);
$picture_name=$_FILES['file_picture']['name'];



mysql_connect($server,$admin) or die("DB Connection error");
mysql_select_db($db) or die("Select DB error");


try{
$string_insert='insert into projects(project_name,code,language,picture,description) values ("'.$file_name.'","'.$code.'","'.$lang.'",'.$picture.','.$descriere.')';



mysql_query($string_insert) or die("Mysql Error nr. 1 in upload.php");

$id_project=id_project2($file_name);
$id_user=id_user($username);

$string_insert2='insert into users_projects(id_user,id_project) values ('.$id_user.','.$id_project.')';


mysql_query($string_insert2) or die("Mysql Error nr. 2 in upload.php");
}
catch (Exception $e){ echo 'Error '.$e->getMessage();}


// creare fisier descriere
if (trim($descriere_text)!="")
{

$cale="user_data"."/".$username."/";

$description_file = $cale.$file_name."_desc.txt";
$file_handle = fopen($description_file, 'w') or die("can't open file");

$descriere_text=str_replace(array("\n","\r")," ",$descriere_text);
$descriere_text=eregi_replace(" +"," ",$descriere_text);

try{
	fwrite($file_handle,$descriere_text);
	}
catch (Exception $e) { echo 'Error: ' .$e->getMessage(); }



fclose($file_handle);
}

}



echo '<script type="text/javascript">';
echo 'alert ("'.$mesaj.'");';
echo '</script>';

//header("location:index.php");

?>



This is the code that doesn't work. I know i should use try-catch but i don't wanna modify it because is hard work!
So..., why it gives me the error?
Was This Post Helpful? 0
  • +
  • -

#6 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 06:32 AM

You really should rethink your error checking logic, because the code you have here is a real monster, have you tried to output the $_FILES['file']['type'] and see what it says? :)

if ($_FILES["file"]["type"] != "application/x-rar-compressed") die($_FILES["file"]["type"]);

Was This Post Helpful? 0
  • +
  • -

#7 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 513
  • Joined: 21-December 08

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 12:19 PM

View PostWimpy, on 8 Aug, 2009 - 05:32 AM, said:

You really should rethink your error checking logic, because the code you have here is a real monster, have you tried to output the $_FILES['file']['type'] and see what it says? :)

if ($_FILES["file"]["type"] != "application/x-rar-compressed") die($_FILES["file"]["type"]);


Thanks allot! It should have been "application/x-rar", but the compressed thing is what i found when i search google for rar mime type.
Now i don't have to rethink my monster code.

This post has been edited by livium: 08 August 2009 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#8 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Cannot upload rar files when site uploaded on server

Posted 08 August 2009 - 03:10 PM

Happy your problem got solved! Nevertheless, you really should rethink your logic anyways to increase maintainability! :) But, as with anything else, it's simply a suggestion!

View Postlivium, on 8 Aug, 2009 - 09:19 PM, said:

View PostWimpy, on 8 Aug, 2009 - 05:32 AM, said:

You really should rethink your error checking logic, because the code you have here is a real monster, have you tried to output the $_FILES['file']['type'] and see what it says? :)

if ($_FILES["file"]["type"] != "application/x-rar-compressed") die($_FILES["file"]["type"]);


Thanks allot! It should have been "application/x-rar", but the compressed thing is what i found when i search google for rar mime type.
Now i don't have to rethink my monster code.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1