13 Replies - 2894 Views - Last Post: 13 August 2009 - 08:22 AM Rate Topic: -----

#1 livium  Icon User is offline

  • D.I.C Addict

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

Cannot upload file when site is on server (works on localhost)

Posted 09 August 2009 - 12:48 PM

Hello
i have this site : http://freecode.ueuo.com. On my localhost it works to upload a file. But it does not work on the url i have given you. Or, better said, it works only partially. I mean it put the file info in my mysql database, but it does not put the actual file on the server (it doesn't uploads). I read in the instructions the hosting site gave me that i must set the file to chmod 644, and also the directory in which i upload the file. I did that but it is still useless.

If i upload the file manually through the hosting site manage panel, it works. So it is not something to do with restrictions.

So..., what can it be. I repeat that it works on my localhost.

This post has been edited by livium: 09 August 2009 - 12:49 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Cannot upload file when site is on server (works on localhost)

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Cannot upload file when site is on server (works on localhost)

Posted 09 August 2009 - 12:49 PM

How big is the file that you're trying to upload?? Also try setting the directory to 644 or 777 (you should remove 777 once done) not the file.

EDIT: And please, remove that stupid alert().

This post has been edited by MageUK: 09 August 2009 - 12:50 PM

Was This Post Helpful? 0
  • +
  • -

#3 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 09 August 2009 - 12:59 PM

View PostMageUK, on 9 Aug, 2009 - 11:49 AM, said:

How big is the file that you're trying to upload?? Also try setting the directory to 644 or 777 (you should remove 777 once done) not the file.

EDIT: And please, remove that stupid alert().




It is small. 250kb. I've set everything to 644. The standard value is 777 isn't it ?


PS: You mean the alert which tells you that you are not sign in? If I remove that than nothing will work because it is essential to be sign in when uploading a file.

This post has been edited by livium: 09 August 2009 - 01:01 PM

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 file when site is on server (works on localhost)

Posted 09 August 2009 - 01:03 PM

777 is not the standard value it is the value to give all rights to modify/delete/create to the specified folder/file! :)

View Postlivium, on 9 Aug, 2009 - 09:59 PM, said:

View PostMageUK, on 9 Aug, 2009 - 11:49 AM, said:

How big is the file that you're trying to upload?? Also try setting the directory to 644 or 777 (you should remove 777 once done) not the file.

EDIT: And please, remove that stupid alert().




It is small. 250kb. I've set everything to 644. The standard value is 777 isn't it ?


PS: You mean the alert which tells you that you are not sign in? If I remove that than nothing will work because it is essential to be sign in when uploading a file.

Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Cannot upload file when site is on server (works on localhost)

Posted 09 August 2009 - 01:05 PM

View Postlivium, on 9 Aug, 2009 - 11:59 AM, said:

It is small. 250kb. I've set everything to 644. The standard value is 777 isn't it ?


PS: You mean the alert which tells you that you are not sign in? If I remove that than nothing will work because it is essential to be sign in when uploading a file.

The standard is not 777, no, as mentioned above it's what gives everyone full control over the folder.

No I don't mean that alert I mean the Firefox one, it's very annoying when you're using a better browser.
Was This Post Helpful? 0
  • +
  • -

#6 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 12 August 2009 - 12:06 PM

So... What can i do? I changed the directory where i upload files to 644, and also the files. It doesn't work to upload files still.

This is what they told me (from server) for the first time:

Take care with file permissions specially with FULL - 777!!! Once installed, set permissions for script configuration file to 644.

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

Was This Post Helpful? 0
  • +
  • -

#7 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Cannot upload file when site is on server (works on localhost)

Posted 12 August 2009 - 12:14 PM

This is nothing to do with a script configuration file, use 777. You *need* to be able to write, that's the "security risk".
Was This Post Helpful? 0
  • +
  • -

#8 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 12 August 2009 - 12:16 PM

View PostMageUK, on 12 Aug, 2009 - 11:14 AM, said:

This is nothing to do with a script configuration file, use 777. You *need* to be able to write, that's the "security risk".


So.. you suggest to change the chmod to the directory where i save files to 777 ? And also to the files?
Was This Post Helpful? 0
  • +
  • -

#9 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 12 August 2009 - 12:30 PM

View Postlivium, on 12 Aug, 2009 - 11:16 AM, said:

View PostMageUK, on 12 Aug, 2009 - 11:14 AM, said:

This is nothing to do with a script configuration file, use 777. You *need* to be able to write, that's the "security risk".


So.. you suggest to change the chmod to the directory where i save files to 777 ? And also to the files?


Well, I did that. And i have the same problem.

This post has been edited by livium: 13 August 2009 - 07:56 AM

Was This Post Helpful? 0
  • +
  • -

#10 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 13 August 2009 - 07:56 AM

I just don't know what to do. This is the code for uploading. I repeat that this code works on my localhost but on server it does not in the sense that it does not upload the file to server.

So i have tried to set chmod to 777. But it still does not work.

$description_file is the path to the file which i want to upload (including the file)
"user_data"."/".$username is the directory where i want to upload the file


This are the chmod lines in the code. I've tried with 0777 too but it does not work.
chmod($description_file, 0644);
chmod("user_data"."/".$username, 0644);
chmod($description_file, 0644);



<?php

$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") $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='238250';
$admin='238250';
$password_mysql="nevermind";

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



mysql_connect($server,$admin,$password_mysql) 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";

chmod($description_file, 0644);   
chmod("user_data"."/".$username, 0644); 

$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);
chmod($description_file, 0644);	
}
catch (Exception $e) { echo 'Error: ' .$e->getMessage(); }



fclose($file_handle);
}

}



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

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

?>


Was This Post Helpful? 0
  • +
  • -

#11 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Cannot upload file when site is on server (works on localhost)

Posted 13 August 2009 - 08:00 AM

Set the CHMOD via FTP, you don't need to chmod the file, just the directory.
Was This Post Helpful? 1
  • +
  • -

#12 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 13 August 2009 - 08:07 AM

View PostMageUK, on 13 Aug, 2009 - 07:00 AM, said:

Set the CHMOD via FTP, you don't need to chmod the file, just the directory.



Ok, so i will chmod only the directory. But what do you mean to set the chmod via FTP? I don't understand that.
Can you bee more specific?
Was This Post Helpful? 0
  • +
  • -

#13 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 13 August 2009 - 08:14 AM

AAA... I see now on the server page. I will change it and see if it works.

This post has been edited by livium: 13 August 2009 - 08:15 AM

Was This Post Helpful? 0
  • +
  • -

#14 livium  Icon User is offline

  • D.I.C Addict

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

Re: Cannot upload file when site is on server (works on localhost)

Posted 13 August 2009 - 08:22 AM

Yuppyyyyy.
I love you man. Now it works.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1