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
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
Share on other sites

The problem with:

 

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

 

is the missing "/" in the path. Like ToonMariner said he is not sure if $_SERVER['DOCUMENT_ROOT'] has "/" or not ;)

 

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.