simun Posted May 29, 2009 Share Posted May 29, 2009 tjis is my line of code $this->uploadLocation = "../../static/gallery/products/"; after products/ i need to put $_GET['id'] but i cant make it work someone help? Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/ Share on other sites More sharing options...
ToonMariner Posted May 29, 2009 Share Posted May 29, 2009 $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!) Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844859 Share on other sites More sharing options...
simun Posted May 29, 2009 Author Share Posted May 29, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844867 Share on other sites More sharing options...
Dathremar Posted May 29, 2009 Share Posted May 29, 2009 I suggest You echo out the location and see if it matches You requirements. That would help You find whats missing in the path Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844874 Share on other sites More sharing options...
simun Posted May 29, 2009 Author Share Posted May 29, 2009 thanks for reply but i resolved it with tis line of code $this->uploadLocation = "../../static/gallery/products/" . $_GET['id'] .DIRECTORY_SEPARATOR; Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844875 Share on other sites More sharing options...
Dathremar Posted May 29, 2009 Share Posted May 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-844885 Share on other sites More sharing options...
ToonMariner Posted May 29, 2009 Share Posted May 29, 2009 $_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; Quote Link to comment https://forums.phpfreaks.com/topic/160133-php-help-please/#findComment-845361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.