Esempio n. 1
0
        /// <summary>
        /// Reads PhpBytes from file using the PhpStream.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        internal static PhpBytes ReadPhpBytes(string filename)
        {
            PhpBytes bytes;

            using (PhpStream stream = PhpStream.Open(filename, "rb", StreamOpenOptions.Empty, StreamContext.Default))
            {
                if (stream == null)
                {
                    return(null);
                }

                try
                {
                    bytes = PhpStream.AsBinary(stream.ReadContents());
                    if (bytes == null || bytes.IsEmpty())
                    {
                        return(null);
                    }
                }
                catch
                {
                    return(null);
                }
            }

            return(bytes);
        }
Esempio n. 2
0
        public static PhpString file_get_contents(Context ctx, QueryValue <LocalVariables> localsData, string path, FileOpenOptions flags = FileOpenOptions.Empty, PhpResource context = null, int offset = -1, int maxLength = -1)
        {
            var sc = StreamContext.GetValid(context, true);

            if (sc == null)
            {
                return(default(PhpString));
            }

            using (PhpStream stream = PhpStream.Open(ctx, path, "rb", ProcessOptions(ctx, flags), sc))
            {
                if (stream == null)
                {
                    return(default(PhpString));
                }

                // when HTTP protocol requested, store responded headers into local variable $http_response_header:
                if (string.Compare(stream.Wrapper.Scheme, HttpStreamWrapper.scheme, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var headers = stream.WrapperSpecificData as PhpArray;
                    localsData.Value.Locals.SetItemValue(new IntStringKey(HttpResponseHeaderName), (PhpValue)headers);
                }

                //
                //return Core.Convert.Quote(stream.ReadContents(maxLength, offset), ScriptContext.CurrentContext);
                return(stream.ReadContents(maxLength, offset).ToPhpString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Reads PhpBytes from file using the PhpStream.
        /// </summary>
        internal static byte[] ReadPhpBytes(Context ctx, string filename)
        {
            byte[] bytes;

            using (PhpStream stream = PhpStream.Open(ctx, filename, "rb", StreamOpenOptions.Empty, StreamContext.Default))
            {
                if (stream == null)
                {
                    return(null);
                }

                try
                {
                    var element = stream.ReadContents();
                    if (element.IsNull)
                    {
                        return(null);
                    }

                    bytes = element.AsBytes(ctx.StringEncoding);
                }
                catch
                {
                    return(null);
                }
            }

            return(bytes);
        }