Jump to content

php help please


simun

Recommended Posts

$this->uploadLocation = "../../static/gallery/products/" . $_GET['id'];

 

personally I prefer to fully qualify the paths when dealing with files in php.

 

$this->uploadLocation = $_SERVER['DOCUMENT_ROOT'] . "static/gallery/products/" . $_GET['id'];

 

May well help you make this more flexible - depends on requirements of course (need to check if that super global has the trailing slash btw!)

Link to comment
https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844859
Share on other sites

i cant get it work

script says that directory does not exsist but a directory with id name is there...

 

here is my code

 

<?php

class ruverUpload{
var $uploadLocation;

function ruverUpload(){
$this->uploadLocation = $_SERVER['DOCUMENT_ROOT'] . "static/gallery/products/" . $_GET['id'] .DIRECTORY_SEPARATOR;	

}

function setUploadLocation($dir){
$this->uploadLocation = $dir;
}

function showUploadForm($msg='',$error=''){
?>
<div id="container">
<div id="header"><div id="header_left"></div>
<div id="header_main">Dokumenti</div><div id="header_right"></div></div>
<div id="content">
<?php
if ($msg != ''){
echo '<p class="msg">'.$msg.'</p>';
} else if ($error != ''){
echo '<p class="emsg">'.$error.'</p>';

}
?>
<form action="" method="post" enctype="multipart/form-data" >
<center>

<label>File:
<input name="myfile" type="file" size="30" />
</label>
<label>
<input type="submit" name="submitBtn" class="sbtn" value="Upload" />
</label>
</center>
</form>
</div>

</div>
<?php
}

function uploadFile(){
if (!isset($_POST['submitBtn'])){
$this->showUploadForm();
} else {
$msg = '';
$error = '';

//Check destination directory
if (!file_exists($this->uploadLocation)){
$error = "The target directory doesn't exists!";
} else if (!is_writeable($this->uploadLocation)) {
$error = "The target directory is not writeable!";
} else {
$target_path = $this->uploadLocation . basename( $_FILES['myfile']['name']);

if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$msg = basename( $_FILES['myfile']['name']).
" was uploaded successfully!";
} else{
$error = "The upload process failed!";
}
}

$this->showUploadForm($msg,$error);
}

}

}
?>

 

Some help?

Link to comment
https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844867
Share on other sites

$_SERVER['DOCUMENT_ROOT'] does have the trainling slash on some installations and not on others - which is why you have to check.

 

just run this and see what you get

$path = "../../static/gallery/products/" . $_GET['id'] . DIRECTORY_SEPARATOR;
echo $path;
$this->uploadLocation = $path;

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-845361
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.