AbsolutePath() static private method

Merges the path with the current working directory to get a canonicalized absolute pathname representing the same path (local files only). If the provided path is absolute (rooted local path or an URL) it is returned unchanged.
static private AbsolutePath ( string path ) : string
path string An absolute or relative path to a directory or an URL.
return string
Ejemplo n.º 1
0
 /// <summary>Changes the virtual working directory for the current script.</summary>
 /// <param name="ctx">Runtime context.</param>
 /// <param name="directory">Absolute or relative path to the new working directory.</param>
 /// <returns>Returns <c>true</c> on success or <c>false</c> on failure.</returns>
 /// <exception cref="PhpException">If the specified directory does not exist.</exception>
 public static bool chdir(Context ctx, string directory)
 {
     if (directory != null)
     {
         string newPath = PhpPath.AbsolutePath(ctx, directory);
         if (System.IO.Directory.Exists(newPath))
         {
             // Note: open_basedir not applied here, URL will not pass through
             ctx.WorkingDirectory = newPath;
             return(true);
         }
     }
     PhpException.Throw(PhpError.Warning, string.Format(Resources.LibResources.directory_not_found, directory));
     return(false);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Opens a new zip archive for reading.
 /// </summary>
 /// <param name="ctx">Current runtime context.</param>
 /// <param name="filename">The file name of the ZIP archive to open.</param>
 /// <returns>Returns a resource handle for later use with <see cref="zip_read(ZipArchiveResource)"/>
 /// and <see cref="zip_close(ZipArchiveResource)"/> or returns the number of error if
 /// <paramref name="filename"/> does not exist or in case of other error.</returns>
 public static PhpValue zip_open(Context ctx, string filename)
 {
     try
     {
         string fullPath   = PhpPath.AbsolutePath(ctx, filename);
         var    fileStream = File.Open(fullPath, FileMode.Open);
         var    archive    = new ZipArchive(fileStream, ZipArchiveMode.Read);
         return(PhpValue.FromClass(new ZipArchiveResource(archive)));
     }
     catch (FileNotFoundException e)
     {
         PhpException.Throw(PhpError.Warning, e.Message);
         return(ER_NOENT);
     }
     catch (IOException e)
     {
         PhpException.Throw(PhpError.Warning, e.Message);
         return(ER_OPEN);
     }
 }