Hope you help me... I've been at this for the past 2 days and have to admit that I'm stumped.
The OS I'm on is Ubuntu 9.10 Karmic.
I successfully installed and tested Mapserver. For my class project, I have a php script that I am using to create a layer see below....
The error I get when run the script on a cmd line prompt:
Warning: [MapServer Error]: msProcessProjection(): no system list, errno: 2
in /var/www/mapserverdocs/ms4w/apps/world/mapscripts/staticwms.php on line 16
Warning: Failed to open map file static.map in /var/www/mapserverdocs/ms4w/apps/world/mapscripts/staticwms.php on line 16
Fatal error: Call to a member function owsdispatch() on a non-object in /var/www/mapserverdocs/ms4w/apps/world/mapscripts/staticwms.php on line 18
PHP SCRIPT:
<?php
if (!extension_loaded("MapScript")) dl("php_mapscript");
$request = ms_newowsrequestobj();
foreach ($_GET as $k=>$v) {
$request->setParameter($k, $v);
}
$request->setParameter("VeRsIoN","1.0.0");
ms_ioinstallstdouttobuffer();
$oMap = ms_newMapobj("static.map");
$oMap->owsdispatch($request);
$contenttype = ms_iostripstdoutbuffercontenttype();
if ($contenttype == 'image/png') {
header('Content-type: image/png');
ms_iogetStdoutBufferBytes();
} else {
$buffer = ms_iogetstdoutbufferstring();
echo $buffer;
}
ms_ioresethandlers();
?>
I made the directory and files world wide rwx just to make sure it was not a permissions issue
Any help would be greatly appreciated!!
Thanks
Chris
As meagar said, the issue is probably that this line:
$oMap = ms_newMapobj("static.map");
is unable to find "static.map". The current working directory of PHP is very often not what you'd expect it to be. Try making the path be relative to the current script. If static.map is in the same directory as static.map, try this code:
$mapPath = dirname(__FILE__).'/static.map';
$oMap = ms_newMapobj($mapPath);
$oMap->owsdispatch($request);
if static.map is at, let's say, /var/www/mapserverdocs/ms4w/apps/world/mapfiles/static.map, then try:
$mapPath = dirname(__FILE__).'/../static.map';
$oMap = ms_newMapobj($mapPath);
$oMap->owsdispatch($request);
Notice the */../*static.map. dirname(__FILE__) will return the name of the directory of the PHP file you place that code in.
Related
I've got a php problem.
I've got a php file that reads data from a .txt file.
This works, with this code:
$filename= "deadlines.txt";
$fp = fopen($filename,"r");
$content = fread($fp, filesize($filename));
$rawArray = setRawArray($content);
$epochAndTitleArray = toEpoch($rawArray);
Now, I want to make it so that this stuff is executed every second, not just once at the start.
So, I tried to fit it into a function, like this:
$filename= "deadlines.txt";
$fp = 0;
$content = 0;
$rawArray = 0;
$epochAndTitleArray = 0;
function readFile(){
$GLOBALS['fp'] = fopen($GLOBALS['filename'], "r");
$GLOBALS['content'] = fread($GLOBALS['fp'], filesize($GLOBALS['filename']));
$GLOBALS['rawArray'] = setRawArray($GLOBALS['content']);
$GLOBALS['epochAndTitleArray'] = toEpoch($GLOBALS['rawArray']);
}
In this case I'm working with globals, before, I did it without, and also left out the lines before the function itself. This was incorrect I think, so I added the globals.
Now, this doesn't work.
It gives me the following error:
Fatal error: Cannot redeclare readFile() in .....on line 28,
this line 28 is the line of the closing } at the end of the function.
Can you guys help me in completing this task?
Thanks already!
readfile is a defined function in php , you cannot redeclare it or redeclare any function using the same name .
for more reference about how to declare valid functions in php
PHP does not support function overloading, nor is it possible to
undefine or redefine previously-declared functions.
Rename 'readFile' to another, readfile() is predefined function 'http://php.net/manual/kr/function.readfile.php'
I use PHP app in Google appengine,
I'm trying to read a input file and write it to an output file in Storage bucket like below.
$input_file = fopen('gs://mybucket/input.csv','r');
$output_file = fopen('gs://mybucket/output.csv', 'w');
And trying to write some date like
while(!feof($input_file)) {
$csv = fgetcsv($input_file,1024);
if(!$csv[0]){
fclose($output_file); //Close the connection when the loop ends
fclose($input_file);
exit(0);
}
fwrite($output_file, $csv[0]."\r\n");
}
It works perfectly, When i try to upload some data in to input file and it successfully write in to output.csv as well. but if i try more than 5 or 6th time it starts to throw an error in appengine logs like below. Any help to troubleshoot this issue will be highly appreciated!
2015-04-08 21:31:29.006 PHP Fatal error: Undefined class constant 'WRITE_SCOPE' in /base/data/home/runtimes/php/sdk/google/appengine/ext/cloud_storage_streams/CloudStorageWriteClient.php on line 214
Update:
I think this is because of opening 2 file streams at same time,
Did some work around and solved this!
$input_file = fopen('gs://mybucket/input.csv','r');
$array_acc = array();
while(!feof($input_file)) {
$csv = fgetcsv($input_file, 1024);
if($csv[0]) array_push($array_acc, $csv[0]);
}
fclose($input_file); //close the file
$acc_count = count($array_acc);
$output_file = fopen('gs://tool-synclio/output.csv','w'); // Open the output file now
while($acc_count > 0){
fwrite($output_file,$array_acc[$acc_count]."\r\n");
$acc_count --;
}
fclose($output_file);
But, I'm still waiting for some one to give better solution.
You have 2 dollar signs in a variable:
fwrite($output_file, $$csv[0]."\r\n");
I am doing a rename so I can move a folder. The move is successful, but I keep getting a warning:
Warning: rename(site_files/259,trash/site_files/259) [function.rename]: No such file or directory in /home/oosman/public_html/lib.php on line 79
This is my code:
$path_parts = pathinfo($file);
$d = $path_parts['dirname'];
$f = $path_parts['basename'];
$trashdir='trash/'.$d;
mkdir2($trashdir);
if(!is_dir($trashdir))
return FALSE;
rename($file, $trashdir.'/'.$f); // this is line 79 where the warning is coming from
Why am I getting this warning?
FYI the mkdir2 is just my recursive mkdir function
function mkdir2($dir, $mode = 0755)
{
if (#is_dir($dir) || #mkdir($dir,$mode)) return TRUE;
if (!mkdir2(dirname($dir),$mode)) return FALSE;
return #mkdir($dir,$mode);
}
This is just because the source or targeting folder does not exist.
This will remove the warning anyway but not the best way to solve the question:
if(file_exists($file) && file_exists($trashdir)){
rename($file, $trashdir.'/'.$f);
}
In order to find out what the problem really is, please check following questions:
1.Does the source file(site_files/259) exist? Does it have an extension like 259.txt?
From your log , I guess the absolute path of the original file should be /home/oosman/public_html/site_files/259.
2.Have you successfully created the target folder? Can you see it on the disk and get TRUE from mkdir2()?
3.I strongly suggest that you use the absolute path but not the relative path when you use rename().
rename('/home/oosman/public_html/site_files/259', '/home/oosman/public_html/trash/site_files/259');
but not
rename('site_files/259', 'trash/site_files/259');
Maybe something wrong with the relative path?
Updated 2014-12-04 12:00:00 (GMT +900):
Since it is not anything mentioned above could you please log something to help me clarify?
Please change
rename($file, $trashdir.'/'.$f);
to
echo "Before moving:\n"
echo "Orgin:".file_exists($file)."\n";
echo "Target parent folder:".file_exists($trashdir)."\n";
echo "Target file:".file_exists($trashdir.'/'.$f)."\n";
rename($file, $trashdir.'/'.$f);
echo "After moving:\n"
echo "Orgin:".file_exists($file)."\n";
echo "Target parent folder:".file_exists($trashdir)."\n";
echo "Target file:".file_exists($trashdir.'/'.$f)."\n";
If this outputs:
Before moving:
Origin:1
Target parent folder:1
Target file:0
Warning: rename(site_files/259,trash/site_files/259) [function.rename]: No such file or directory in /home/oosman/public_html/lib.php on line 83
After moving:
Origin:0
Target parent folder:1
Target file:1
exactly only once, then I am out. If it doesn't, please tell me the difference.
One possibility is simply to hide the warning:
error_reporting(E_ALL & ~E_WARNING);
rename($file, $trashdir.'/'.$f);
error_reporting(E_ALL & ~E_NOTICE);
I am working on a drupal project where i need to write cron that runs in 10 minuts and update database. I am using drupal 7.24 latest version.
I created a seperate PHP file and load drupal full bootstrap as
define('DRUPAL_ROOT',getcwd());
chdir(DRUPAL_ROOT);
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Now i have written a select query using db_select() function and it gave following errors.
Notice: Undefined offset: 5 in DatabaseLog->findCaller() (line 156 of D:\wamp\www\drupal-7.24\includes\database\log.inc).
I did not recognized how to resolved it. Any help will be appreciated.
Thanks,
Raj kishor
I have created one file and i put at root directory and it worked for me . Please check below
echo $_SERVER['DOCUMENT_ROOT'];
chdir($_SERVER['DOCUMENT_ROOT']);
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']); // optional
require_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // load Drupal to use Drupal API
$users = db_select('users', 'u')
->fields('u', array('uid'))
->condition('u.status', 1, '=');
$users->innerJoin('users_roles', 'ur', 'u.uid = ur.uid');
$users = $users->execute();
foreach ($users as $user) {
echo $user->uid;
}
I'm having trouble trying to get attributes from files in my list. The code is:
if ($this->dir = opendir($caminho))
{
$this->itens = array();
$this->itensTotal = 0;
$tipos = array("dir" => 0, "file" => 1);
while ($item = readdir($this->dir))
{
if (!in_array($item, $this->skip))
{
$t = filetype($item);
$this->itens[$tipos[$t] . $item] = array("nome" => $item,
"size" => filesize($item),
"tipo" => $t,
"perm" => fileperms($item));
$this->itensTotal++;
}
}
}
Seeing that my script is 'file.php' and is in the folder 'www'. When it reads it's own folder (www) it works ok and lists all files and directoryies with their attributes. But when it tryies to read eg.: /www/folder/ the function filetype(), filesize() an fileperms() doesn't works! I get these warnings for all itens in the directory:
Warning: filetype() [function.filetype]: Lstat failed for bkp in
D:\UniformServer\UniServer\www\files.php on line 174
Warning: filesize() [function.filesize]: stat failed for bkp in
D:\UniformServer\UniServer\www\files.php on line 176
Warning: fileperms() [function.fileperms]: stat failed for bkp in
D:\UniformServer\UniServer\www\files.php on line 178
It's opens the folder, read it's contents but these functions doesn't woks =s
Notes:
As you can see I'm running it on Windows
$caminho has valids paths
Please, any help will be welcome cause google doesn't helped.
The file operations use the real directory names on the system, not the relative path of the website, and "/www/folder" probably doesn't exist then. From your comment, you would need either: "D:/UniformServer/UniServer/www/folder" or use a relative path from the php script.
I think $item only contain the basename of the file. You should probably prepend the directory path to it, like this: filetype(this->dir . $item).