I'm Using ZendFramework-1.0.4 and I don't have any idea how does it wrap the $_FILE global-variable.
Is it a good idea to use it directly in my Controller?
I need to Upload an image file.
I suppose you can use $_FILES as you whish.
Still, the best way to be sure is to use something like
var_dump($_FILES);
somewhere in you controller ; this way, you'll see if it contains what you expect ;-)
Then, don't forget to use is_uploaded_file ; and, you can use move_uploaded_file to manipulate the file.
Still, if you are using forms, you could take a look at Zend_Form and Zend_Form_Element_File, which will do some work for you.
Hu... Actually : not sure those were present in ZF 1.0.x :-(
As a sidenote : Zend Framework 1.0.4 is quote old (was released in frebruary 2008 ; see the archives page) ; it is no longer maintained, and there have been several versions released since. Would it not be useful for you to update ?
(Would probably require some work, though, for such an update, as lots of things have changed... But there are many components that have been added, and could be useful for your project, too ;-) )
If anyone else still use this version.
I recommend you use the HTTP_Upload class from the sweet PEAR library.
Related
I'm using Dreamweaver CS5. I know that code hinting works in Dreamweaver with own functions/classes, but only if the functions file is included one level from main script.
Here an example:
main_script.php
include(my_functions.php)
this work and all functions which included in my_functions.php will hint when I'm editing the main_script.php (strg + space).
Other example:
main_script.php (own functions not available)
include(global_config.php) (own functions available)
include(my_functions.php) (own functions available)
Do you know if there is some trick or fix in other versions of Dreamweaver? If code hinting would work with several included levels that would make work much easier.
I've searched this site and several others but didn't find anybody with nearly the same problem, maybe somebody here can help.
Thankyou for the Editors you suggest me. I just tried out the PHPStorm and this Support codeHinting with several included files in a Project automaticly.
I just found out that Dreamweaver CS5 also Support this, in a bit other way here is a good tutorial Video for this:
http://tv.adobe.com/de/watch/lerne-dreamweaver-cs5/code-hinting-und-phphilfestellungen/
You can config a custome code hinting under "Site" => "SiteSpecific CodeHints"
Better then nothing ;)
Tom
Not sure if it works in dreamweaver but you could try adding a phpdoc eg:
include('global_config.php');
/* #var $functions Functions */
$functions = new Functions();
This assumes your functions are wrapped in a class
Heads up: I dont have the possibility to rename the classes or use name spaces for this.
Im looking for any crazy way to subvert class redeclaration issues in php. I actually only need 3 static variables from a web application, but the only way to get them requires including a file that declares a user class. However I already have a user class, so I get an error.
I tried to no avail to include the file in a class hoping it would isolate the included file - But no.
I tried reading an interface file I created that just echos the 3 values, but that actually just reads the php code and not the rendered values.
Is there anything like an opto-isolation system for code?
The only think I can think of is using ajax to do it, but it seems super sketchy. Is there a plain php version of this?
(Was a comment, but got too long.) Doesn't sound doable with your constraints. (You might need to show some code.) -- But if you are asking for a crazy way, and the option to rename the classes just applies to not editing the php script, then:
Load the include file into a variable, then transform it, and finally eval:
$source = file_get_contents("user.php");
$source = str_replace("class user", "class workaround_123", $source);
eval($source); // will give you a workaround_user instead of class conflict
Someone will probably comment on the advisability of eval... But it foremost depends on your code/situation if that's an applicable wacky workaround.
Alternatively you could invoke the user fetching code with a separate PHP process :
exec("QUERY_STRING=user=123 php-cgi user.php");
You could tokenize the whole file and go through it "by hand" to find the values you need.
Is it possible with PHP(5) or other Linux tools on an apache debian webserver to get the file requests a single http request made?
for performance reasons i would like to compare them with the cached "version" of my cake app.
non-cached that might be over 100 in some views.
cached only up to 10 (hopefully).
afaik there are 3 main file functions:
file_get_contents(), file() and the manual fopen() etc
but i cannot override them so i cannot place a logRequest() function in them.
is there any other way? attaching callbacks to functions? intercepting the file requests?
This suggestion does not seems intuitive, but you can take look on xdebug - function trace
Once you have xdebug installed and enabled, you can using all sort of configuration to save the profiling into a disk file and you can retrieve it later. Such as profiling results for different URL save into different disk file.
To monitoring file system related functions, you can do a parse of the text file(profiling results) and do a count of matchable functions (programmable or manually)
The way I would do it would be to create a custom function that wraps around the one you need.
function custom_file_get_contents($filename) {
$GLOBALS['file_get_contents_count']++;
return file_get_contents($filename);
}
And just replace all of your calls to file_get_contents with custom_file_get_contents. This is just a rudimentary example, but you get the idea.
Side note, if you want to count how many files your script has included (or required), see get_included_files()
You can use Xdebug to log all function calls
Those so-called "function traces" can be a help for when you are new to an application or when you are trying to figure out what exactly is going on when your application is running. The function traces can optionally also show the values of variables passed to the functions and methods, and also return values. In the default traces those two elements are not available.
http://www.xdebug.org/docs/execution_trace
Interesting question. I'd start with the stream_wrapper ... try to replace them with custom classes.
There is a pecl extention called ADB (Advanced PHP Debugger) that has tow functions that would be very useful for a cse like this - override_function() and rename_function(). You could do something like this:
rename_function('file_get_contents', 'file_get_contents_orig');
function file_get_contents($filename) {
logRequest();
return file_get_contents_orig($filename);
}
It looks like ADB is pretty easy to install, too.
See http://www.php.net/manual/en/book.apd.php
I would like to know how to create a php function that can be installed in php
just like the already built in functions like :
rename
copy
The main point I would like to achieve is a simple php function that can be called from ANY php page on the whole host without needing to have a php function within the php page / needing an include.
so simply I would like to create a function that will work like this :
location();
That without a given input string will output the current location of the file via echo etc
Well, there are a couple of options here. One of them is to actually extend the language by writing an extension. You'd have to muck around with the PHP source code, write it in C, and deal with the Zend Engine internally. You probably wouldn't be able to use this on a shared host and it would be quite time consuming and probably not worth it.
What I would do is put all of your functions into a separate PHP file, say helper_functions.php. Now, go into your php.ini and add the directive: auto_prepend_file = helper_functions.php. This file should be in one of the directories specified in your include_path (that's a php.ini directive too).
What this does is basically automatically put include 'helper_functions.php'; on every script. Each and every request will have these functions included, and you can use them globally.
Read more about auto_append_file.
As others have said, there's probably an easier, better way to do most things. But if you want to write an extension, try these links:
http://docstore.mik.ua/orelly/webprog/php/ch14_01.htm
http://www.tuxradar.com/practicalphp/2/3/0
So you want to extend PHP's core language to create a function called location(), written in C, which could be done in PHP by:
echo __FILE__;
Right. Have fun doing that.
I have a question concerning the design of my project's Code.
In most cases, it is important to separate content from code (HTML mixed with PHP in bigger apps=No good idea, etc.) but how should I handle things like the text of error messages?
Assuming this one message will be only used in one case/PHP file:
MessageBox( 'Something gone wrong, probably your fault' );
or
MessageBox( Lang::error_usersfault );
(Where Lang is a class located in some config file, full of consts)
If you have any experiences (I think every PHP programmer will come across something like this) with things like in the example above - What are they? How do you solve it?
What is the better solution?
May be you'll find php extension gettext useful?
MessageBox(_("Have a nice day"));
PHP Manual of Gettext::gettext