php

Create and store images on the fly

How would I go about catching a request for images that doesn't exist and create them as needed so as not to return a 404? These would then be stored on the server until no longer needed and deleted. The code would preferably be in PHP. Deletion will most likely occur in a cron job. The images would be requested in batches of 10 or so a...

How can I generate a tree structure from a table in a database?

I'm trying to generate a tree structure from a table in a database. The table is stored flat, with each record either having a parent_id or 0. The ultimate goal is to have a select box generated, and an array of nodes. The code I have so far is : function init($table, $parent_id = 0) { $sql = "SELECT id, {$this->parent_id_field},...

Get Latest Entry from Database

How can I get the latest entry by the latest DATE field from a MySQL database using PHP? The rows will not be in order of date, so I can't just take the first or last row. ...

Sql error while running query data type mismatch in criteria expression

I'm getting the following error while running the SQL query given below 'Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005?T in SQLExecDirect in D:\xampp\htdocs\fypphp\functions.php on line 543' INSERT INTO vehicl...

Read echo'ed output from another PHP file

I want 1 PHP file to "run" (include?) another PHP file on the same server, and access its echo'ed output as a string. How do i do this in PHP? Any inbuilt functions to do this? Or any better way of executing another PHP file and getting its output? ...

Getting imagegrabscreen to work

I'm trying to get imagegrabscreen (a GD function) to work with my Apache/Vista PC. I'm using the following code: <?php $im = imagegrabscreen(); header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?> At the moment I get a solid black image, the size of my secondary monitor (1024*768). I'm using Apache 2.2, runing as ...

INSERT Statement after a SELECT in mysql_query

Hi! I'm trying to execute two SQL statements in one mysql_query. $mySql = mysql_query("SELECT itemid, points FROM items WHERE id='1' UPDATE accounts SET userpoints = '1000'"); Is this possible? Thanks! ...

How do I set a cookie on localhost with MAMP + MacOSx + PHP?

I'm developing on my Mac notebook, I use MAMP. I'm trying to set a cookie with PHP, and I can't. I've left off the domain, I've tried using "\" for the domain. No luck. setcookie("username", "George", false, "/", false); setcookie("name","Joe"); I must be missing something obvious. I need a quick and simple solution to this. Is there...

PHP temp file names for uploads colliding

When a user uploads a file, randomly it gets replaced by another user's upload, I've finally tracked down the issue to PHP and the tmp file name being reused. Is there a way to fix this? Is there a way to make better random names? It seems to degrade over time, as in the random file name seed gets weaker? This is on PHP 5.2.8 and FreeBSD...

Tools for cleaning garbage PHP

I just inherited a 70k line PHP codebase that I now need to add enhancements onto. I've seen worse, at least this codebase uses an MVC architecture and is object oriented. However, there is no templating system and many classes are deprecated - only being called once. I think my method might be the following: Find all the files on t...

Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac...

I've looked for other questions, but could not find any... I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using http://localhost/ I come from a PHP background and always used MAMP before. But I want to get everythin...

PHP nested loop behaving unexpectedly

I have an array which contains the categories for a particular article ($link_cat). I'm then using mysql_fetch_array to print out all of the categories available into a list with checkboxes. While it's doing this I want it to compare the value it's on, to a value from the other array. If there is a match, then it means that one of the ca...

How can my PHP script tell whether the server is busy?

I want to run a cron job that does cleanup that takes a lot of CPU and Mysql resources. I want it to run only if the server is not relatively busy. What is the simplest way to determine that from PHP? (for example, is there a query that returns how many queries were done in the last minute? ...) ...

How to Check if File is ASCII or Binary in PHP

Is there a quick, simple way to check if a file is ASCII or binary with PHP? DUPLICATE http://stackoverflow.com/questions/620993/determining-binary-text-file-type ...

Where should I sell my website?

It is not 'complete' and earns no money at the moment, however I think it is a good idea and the design is very good. It is backed by a SQL database and is written in PHP. ALL the design and coding are original (done by myself). I just don't have time to keep working on it, but it seems like a waste to let it die. Given that the person ...

Split multiple SQL statements into individual SQL statements

Intro note: I'm hoping a library or routine exists to do this, but I haven't been able to find anything like this. I'm really looking for direction and advice on where to start... Here is the situation: I have a block of SQL commands coming as plain text. It might be one SQL commands or several. I need a way to split multiple SQL comman...

c# translation to PHP Array key

I am trying to call a PHP Magento store web service from C#. How do I create this type of an "ARRAY KEY" in C# to pass to PHP: call( $sessionId, 'product_stock.update', array('Sku', array('qty'=>50, 'is_in_stock'=>1)) ); Here is a link to the magento wiki for the call: http://www.magentocommerce.com/wiki/doc/webservice...

Best way to escape strings for sql inserts?

What is the best way to escape strings for sql inserts, updates? I want to allow special characters including ' and ". Is the best way to search and replace each string before I use it in an insert statement? Thanks Duplicate of: http://stackoverflow.com/questions/568995/best-way-to-defend-against-mysql-injection-and-cross-site-scrip...

php image uploading and permissions

Can you please tell me if there are ways to upload images with php without chmoding the directory with `ftp_site($conn_id, 'CHMOD 0777, /www/images/thumbs');` to circumvent [function.move-uploaded-file]: failed to open stream: Permission... Thanks! ...

How do you get PHP to return the timezone abbreviation AEST?

I can't seem to find a way to get Pear's Date class (or PHP's date function) to return AEST as the timezone abbreviation for the timezone Australia/Melbourne. It always returns EST. I tried all the ways of printing out the timezone available in Date::format, format2, format3. Anyone know how to fix this? I'm running PHP 5.1.6, Pear Date ...