webForumDet fria alternativet

safe mode?

PHP

2 svar · 285 visningar · startad av Prime_66

Medlem sedan aug. 2004290 inlägg
Frågan#1

Jag bytte webbhotell precis. På det nya kör dom php5 istället för 4 samt att safe-mode verkar vara påslaget. Är det därför unlink() och chmod() inte fungerar?

Fortsätting:

Jag skippar att man kan ta bort filer. Får göra det manuellt istället. Men ladda upp måste ju fungera. Det sjuka nu är att det funkar att ladda upp filer om det redan finns en fil som heter som den man laddar upp i mappen. Finns inte en fil med samma namn sakpar ingen ny fil. Har väl oxå o göra med safemode antar jag..

Förmodligen orkar ingen hjälpa mig med detta men jag vore grymmt tacksom. Vad måste jag ändra för att följande kod ska fungera i safemode? (Obs! Koden är inte optimerad o speciellt "fin" nu som ni ser ):

Php-sida1

<?php
//Declare session variable
session_start();
$musicmak_account = $_SESSION['login'];

//User pressed update! 
if (isset($_POST['update'])){
//Link to database-connect file
include("../../musicmaker/mylibrary-connect.inc.php");
//Create connection
$connID = connect_to_mylibrary(); 
$artist = $_POST['artist'];
$writer=$_POST['writer'];
$producer=$_POST['producer'];
$mixer=$_POST['mixer'];
$other=$_POST['other'];

$usertype= $artist.$writer.$producer.$mixer.$other;

$update_usertype ="UPDATE musicmakers SET usertype ='$usertype' WHERE musicmak_account='$musicmak_account'";
mysql_query($update_usertype) or die("rad 19");
//Update presenation

$presentation = $_POST['presentation'];
$update_presentation ="UPDATE musicmakers SET musicmak_presentation ='$presentation' WHERE musicmak_account='$musicmak_account'";
mysql_query($update_presentation) or die("rad 19");

header('location: ../musicmakpresentation.php'); break;
}
//User want´s to sace comment for a image
if ($_POST['action']=="save_comment"){
//Link to database-connect file
include("../../musicmaker/mylibrary-connect.inc.php");
//Create connection
$connID = connect_to_mylibrary(); 
//Update comment
$image_id = $_POST['image_id'];
$commentpost="comment".$image_id;
$comment = $_POST[''.$commentpost.''];
$update_comment = "UPDATE musicmakers_images SET comment='$comment' WHERE musicmakers_images_id='$image_id'";
mysql_query($update_comment) or die ("rad 36");
header('location:../musicmakpresentation.php');
}

require_once('Uploader.class.php');

//Create new instance of class
$file = &new Uploader('userfile');

if( $file->isUploaded() )
{
  
if( $file->checkSize(200000) && $file->checkType() && $file->checkDimension() )
  {
    //Name of dir
	if( $file->saveTo('musicmaker_images/%s') )
    {
	header('location: ../musicmakpresentation.php');break;
      echo sprintf('<p>Filen %s laddades upp utan problem!</p>', $file->getInfo('name'));

    }
    else
    {
	$errormsg = sprintf('<p class="normalitenred">Kunde inte spara filen %s...</p>', $file->getInfo('name'));
	 header('location: ../musicmakpresentation.php');
    }
  }
  else
  {
    $errormsg ="Filen du försöker ladda är inte godkänd. Max filstorlek 50kb, max 50 * 50 pixlar.";
	//If user is coming from multiple image upload
	if(isset($_POST['upload_extra'])){
	echo '
	<HTML> 
	<HEAD>
	<script>
	function MM_goToURL() {
	  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location=\'"+args[i+1]+"\'");
	}

	</script>
	</head>
	<body>';
	
	//Here I redirect in a special way just for the anchor!!
	echo '<img src="../../Images/trans.gif" width="1" height="1" onload="MM_goToURL(\'parent.frames[\\\'mainFrame\\\']\',\'../musicmakpresentation.php?errormsg2=Filen du försöker ladda är inte godkänd. Godkända format är: JPG, GIF och PNG. Max filstorlek 50kb och max 50 * 50 pixlar.#bottom\');return document.MM_returnValue">';
	echo '</body></html>';
	}else{
	header('location:../musicmakpresentation.php?errormsg='.$errormsg.'');
	}

  }
}

?>

o här kommer class-filen:

<?php

	//Declare session variable

	session_start();

	$musicmak_account = $_SESSION['login'];

 	//Link to database-connect file

    include("../../conn/mylibrary-connect.inc.php");

    //Create connection

    $connID = connect_to_mylibrary();  

	

	if(!isset($_POST['upload_extra'])){

	$get_link ="SELECT musicmak_prespicturelink FROM musicmakers WHERE musicmak_account='$musicmak_account'";

	$result = mysql_query($get_link) or die("rad 12");

	$row=mysql_fetch_array($result);

	$filelink = $row['musicmak_prespicturelink'];

	$file = "musicmaker_images/".$musicmak_account.".jpg";

		if ($filelink!=NULL){

		unlink($file);

		$deletelink = "UPDATE musicmakers SET musicmak_prespicturelink=NULL WHERE musicmak_account ='$musicmak_account'";

		mysql_query($deletelink) or die ("rad 14");

		}

	}

	

	if(isset($_POST['upload_extra'])){

	//Check how many images there are in the database

	$result33 = @mysql_fetch_array(@mysql_query("SELECT COUNT(*) AS cntRows FROM musicmakers_images WHERE musicmak_account='$musicmak_account'"));

    $antal = $result33[cntRows];

		if ($antal>=5){

		header('location: ../musicmakpresentation.php');break;

		}

	}

class Uploader

{

  var $_file;

  var $_musicmak_account; 

  //

  //~ object Uploader( string $field )

  //

  

  function Uploader($field)

  {

    $this->_file = !empty($_FILES[$field]['name']) ? $_FILES[$field] : false;

  $this->_musicmak_account = $_POST['musicmak_account'].".jpg";

}

  

  //

  //~ bool isUploaded( void )

  //

  

  function isUploaded()

  {

    return ( $this->_file !== false );

  }

  

  //

  //~ bool checkSize([ int $maxSize ])

  //

  

  function checkSize($maxSize = 200000)

  {

    return ( $this->_file['size'] <= $maxSize );

  }

  

  //

  //~ bool checkType( array $allowedTypes )

  //

  

  function checkType()

  {

   	//Get info from the file into array

	/* Returns an array with 4 elements. Index 0 

    contains the width of the image in pixels. Index 1 

    contains the height. Index 2 is a flag indicating the t

    ype of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 

    7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 

    11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond

    to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with

    the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

	*/

	$checkfile = getimagesize($this->_file['tmp_name']);

	//Image is gif, jpg or png?

	if ($checkfile[2]==1 || $checkfile[2]==2 || $checkfile[2]==3){

	return true;

	}

	 

  }

function checkDimension()

  {

   	//Get info from the file into array

	/* Returns an array with 4 elements. Index 0 

    contains the width of the image in pixels. Index 1 

    contains the height. Index 2 is a flag indicating the t

    ype of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 

    7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 

    11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond

    to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with

    the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

	*/

	$checkfile = getimagesize($this->_file['tmp_name']);

	//Check the width and height

	if ($checkfile[0]<=500 || $checkfile[1]<=500){

	return true;

	}

	 

  }

  

  //

  //~ bool saveTo( string $target [, bool $overwrite ] )

  //

  

  function saveTo($target, $overwrite = true)

  {

    //Give Filename here

	

	if (isset($_POST['upload_extra'])){

	$target = sprintf($target, rand().$this->_musicmak_account);

	}else{

	$target = sprintf($target, $this->_musicmak_account);

	}

    

    if( !is_file($target) || ( $overwrite == true ))

    {

      

	  $moved = @move_uploaded_file($this->_file['tmp_name'], $target);

	  

    }

    

	//Write to database. First if the user came from 5 pictures

	if (isset($_POST['upload_extra'])){

	$this->_musicmak_account = $_POST['musicmak_account'];

	$link = "upload_image/".$target;

	$linkmod = $target;

	$insert_imagelink ="INSERT INTO musicmakers_images (musicmak_account,comment,picture_link,musicmakers_images_id) VALUES

	('$this->_musicmak_account',NULL,'$link',NULL)";

	}else{

	$this->_musicmak_account = $_POST['musicmak_account'];

	$link = "upload_image/musicmaker_images/".$this->_musicmak_account.".jpg";

	$linkmod = "musicmaker_images/".$this->_musicmak_account.".jpg";

	$insert_imagelink ="UPDATE musicmakers SET musicmak_prespicturelink ='$link' WHERE 

	musicmak_account = '$this->_musicmak_account'";

	}

	mysql_query($insert_imagelink) or die("rad 103");

	chmod($linkmod, 0755);

	return ( isset($moved) && $moved == true );

	

  }

  

  //

  //~ mixed getInfo( string $key )

  //

  

  function getInfo($key)

  {

    return isset($this->_file[$key]) ? $this->_file[$key] : false;

  }

}

?>

:p :p

Medlem sedan jan. 20059 inlägg
#2

Jag orkade inte gå igenom all din kod, men jag tycker att det låter som om du inte har rätt rättigheter satta på filerna som du försöker chmod'a eller unlink'a.
Ta en titt på det och se också till att användaren som kör scripten har rätt att skriva till katalogen du laddar upp till.

Medlem sedan aug. 2004290 inlägg
#3

Problemet är kanske att det inte går att sätta skrivrättigheter för group och others på mappen där bilderna ska landa. Alltså det går inte göra på ftpn alltså. Även om jag manuellt sätter chmod till 777 på en bild som ligger i en mapp o försker ta bort den via webbläsaren funkar det inte. Det står access denied..

270 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849
121 ms — deklarationer (db)
0 ms — hämta statistik (cache)
144 ms — hämta tråd, inlägg och bilagor (db)
124 ms — ändringar (db)