|
Just to clarify aswell:
= is an assignment operator.
== is the comparison operator as mentioned above.
=== is another comparison operator I call identity, which checks for equality AND type.
As PHP is not strongly typed, a variable can change types dynamically at runtime.
Example:
$a = 2;
$b = "2";
A comparison would be like this:
if($a == $b)
{
}
..would be TRUE, as they have the same value, but one is an integer and one is a string.
if($a === $b)
{
}
.. would be FALSE, because they have matching values but different types!
For me, understanding this in the beginning helped me to write reliable condition tests for websites and applications.
|
|
|
|
|
flashery wrote: If you run this in a browser you can see the form.
PHP doesn't run in a browser, it runs in the web server. If you open a PHP file directly in a browser (by File->Open...) instead of loading it from a server the PHP code won't get executed.
|
|
|
|
|
I run this stuff using my local web server xampp in localhost.
|
|
|
|
|
I think you might have a syntax error.
if you have to check something, then the if statement should be:
if($submit == true)
if($submit = true) -> is setting submit to true not checking.
Hope this helps.
|
|
|
|
|
This is an odd error and I hope someone has seen it before.
I have a script that is called from other scripts. It also runs from the commandline and is used to ftp files to various destinations. One is to a google upload site and it looks to work 2 out of 3 runs with one time reporting this error
Warning: ftp_put(): '': command not understood.
Using a google search, I have found reference to "ftp_put(): 'STOR':" errors but nothing on the empty string I have.
What else gets me is this does not fail always, just once in a while. I can use the same parameters too...sometimes it fails but usually it is good.
ideas?
Chris J
www.redash.org
|
|
|
|
|
Reading the comments in the PHP Manual ... http://php.net/manual/en/function.ftp-put.php[^] you are not the only one to suffer. In the comments various possible solutions are suggested.
Let us know which, if any, provides a better answer.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
I will have to get back to you in a few, this got pushed back by two other projects....grrrr!
Thanks for the response tho.
Chris J
www.redash.org
|
|
|
|
|
Hi all;
I am create a page with data form with phot upload capability and I don't seem to be getting it right. Below is what I have done so far but not working.
index.php
<pre><?php
include_once 'includes/helpers.inc.php';
require_once 'classes/CommonData.php';
?>
<?php
if (isset ($_GET['upload'])){
if (isset($_GET['destination']) && isset ($_GET['allowedFiles'])) {
$allowedFiles = explode(',', $_GET['allowedFiles']);
if (sizeof($allowedFiles) == 0)
$allowedFiles = $_GET['allowedFiles'];
if (in_array($_FILES["file"]["type"], $allowedFiles)) {
if ($_FILES['file']['error'] > 0) {
$src = '';
$imgMsg = "Return code: " . $_FILES['file']['error'];
} else {
if ($_FILES['file']['size'] > $_GET['maximumFileSize']) {
$src = '';
$imgMsg = 'File size to large. Must be less or equals 10KB.';
} else {
if (file_exists($_GET['destination'] . $_FILES['file']['name'])) {
$src = '';
$imgMsg = $_FILES['file']['name'] . ' already exists.';
} else {
move_uploaded_file($_FILES['file']['tmp_name'] ,
$_GET['destination'] . $_FILES['file']['name']);
$src = $_GET['destination'] . $_FILES['file']['name'];
$imgMsg = '';
echo $src;
}
}
}
} else {
$src = '';
$imgMsg = 'Invalid file type.';
}
} else {
$src = '';
$imgMsg = 'File destination not specified.';
}
$surname = '';
$otherNames = '';
$contactAddress = '';
$email = '';
$phone = '';
$occupation = '';
$officeAddress = '';
include 'views/registration.php';
} elseif (isset ($_GET['registration'])) {
$src = '';
$imgMsg = '';
$surname = '';
$otherNames = '';
$contactAddress = '';
$email = '';
$phone = '';
$occupation = '';
$officeAddress = '';
include 'views/registration.php';
} else {
include 'views/home.php';
}
?>
registration.php
<pre><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php setPageTitle('Home'); ?></title>
<link href="styles/site.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="scripts/jquery-1.6.2.js"></script>
<script type="text/javascript" src="scripts/utility.js"></script>
<script type="text/javascript">
function getState(countryId) {
var strURL="shared/finder/_find-states-by-country-id.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('statediv').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
$(function() {
$("#upload").click(function() {
if ($("#file").val().length == 0) {
$("#imgMsg").html('File not specified for upload.');
return false;
}
$.ajax({
url: 'index.php?upload&destination=' + $("#destination").val() + '&allowedFiles=' + $("#allowedFiles").val(),
type: 'POST',
success: function(result){
$("#test").html(result);
}
});
return true;
});
});
</script>
</head>
<body>
<div id="container">
<?php include 'shared/_public-header.php'; ?>
<!--
<div id="main">
<div id="sidebar">
</div>
<div id="content">
<h1>Welcome</h1>
<form action="submit-registration" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td>Surname:</td>
<td><input type="text" id="surname" name="surname" value="<?php htmlOut($surname); ?>" /></td>
</tr>
<tr>
<td>Other Names:</td>
<td><input type="text" id="otherNames" name="otherNames" value="<?php htmlOut($otherNames); ?>" /></td>
</tr>
<tr>
<td>Contact Address:</td>
<td><input type="text" id="contactAddress" name="contactAddress" value="<?php htmlOut($contactAddress); ?>" /></td>
</tr>
<tr>
<td>Country:</td>
<td>
<select id="country" name="country" onChange="getState(this.value)">
<option value="">[Select Country]</option>
<?php
$commondData = new CommonData();
$countries = $commondData->getCountries();
if (sizeOf($countries) > 0) {
foreach($countries as $country) {
?>
<option value="<?php echo $country['countryId']; ?>"><?php htmlOut($country['name']); ?></option>
<?php } } ?>
</select>
</td>
</tr>
<tr>
<td>State:</td>
<td>
<div id="statediv">
<select id="state" name="state">
<option value="">[Select country first]</option>
</select>
</div>
</td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="email" id="email" name="email" value="<?php htmlOut($email); ?>" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" id="phone" name="phone" value="<?php htmlOut($phone); ?>" /></td>
</tr>
<tr>
<td>Occupation:</td>
<td><input type="text" id="occupation" name="occupation" value="<?php htmlOut($occupation); ?>" /></td>
</tr>
<tr>
<td>Office Address:</td>
<td><input type="text" id="officeAddress" name="officeAddress" value="<?php htmlOut($officeAddress); ?>" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</td>
<td>
<span id="test"></span>
<img name="photo" border="1" src="<?php echo $src; ?>" id="photo" width="120px" height="120px" /><br />
<?php ?>
<!--
<input type="file" name="file" id="file" /><br />
<input type="button" id="upload" value="Upload" /><span id="imgMsg"><?php echo $imgMsg; ?></span>
<input type="hidden" id="destination" name="destination" value="uploads/member/photo/" />
<input type="hidden" id="allowedFiles" name="allowedFiles" value="image/jpeg" />
<input type="hidden" id="maximumFileSize" name="maximumFileSize" value="10000" />
<!--
</td>
</tr>
</table>
</form>
</div>
</div>
<!--
<?php include 'shared/_public-footer.php'; ?>
</div>
</body>
</html>
What am I getting wrong. Please help.
|
|
|
|
|
in your form tag one attribute is missing. Without that attribute browser wont upload file
enctype="multipart/form-data"
I know I am coward since the day I know that fortune favors the brave
|
|
|
|
|
johny10151981 wrote: in your form tag one attribute is missing. Without that attribute browser wont upload file
enctype="multipart/form-data"
Thanks for this.
I have got it working with uploadify [uploadify].
I am very grateful.
|
|
|
|
|
I think this belongs better in the forum as I believe the problem to be on the PHP side. What I'm doing is creating a table dynamically that has some JavaScript function calls in it (well I'm trying to). The page is displaying ok in Chrome and Firefox but IE is complaining about it and not displaying at all. However in Chrome and Firefox it's not "working" just displaying right. this is the code I'm trying to use...
$display_string .= "<td><a href='javascript:choice('".$row .$col ."')'><img src='images/o.jpg' border=0 height=100 width=100 name='" .$row .$col ."' alt='Open'></a></td>";
When you hover over one of the cells on the loaded page you see javascript:choice(. It should read something like javascript:choice(A3) If I do an inspect element with chrome I get
<img src="images/o.jpg" border="0" height="100" width="100" name="B2" alt="Open"> so it appears the issue is in the creation of the javascript call?
Thanks in advance!!
|
|
|
|
|
You need to properly match up your quotes - you used a single quote for href= and then the closing quote was just inside the javascript function. Try this:
$display_string .= "<td><a href=\"javascript:choice('{$row}{$col}')\"><img src='images/o.jpg' border=0 height=100 width=100 name='{$row}{$col}' alt='Open'></a></td>";
I've replaced the outer single quotes with escaped double quotes. I've also put the $row and $col variables into the string so that the '.' operator is not required, but that's just my personal preference.
|
|
|
|
|
Now I see what I did wrong in my other version, I forgot the escape character... the joys of learning new languages. Thanks, it seems to be working now.
Putting a variable inside {} adds it to a string? I didn't know that.
I really appreciate the help!!
|
|
|
|
|
|
Thanks for the link, that really helps
|
|
|
|
|
At the moment, I have index.php located at the root. I want to have it parse all my URLs and delegate the workload to the correct code (via URL rewriting). I may be a bit nit-picky, but I'd like to know if there's an elegant solution to neatly separating the request URL and the key-value pairs of the query?
My index.php looks like this:
<?php
header('Content-Type: text/plain; charset=utf-8');
echo 'Debug Output';
echo "\n\n";
echo 'Request ($_SERVER["REQUEST_URI"]): "'.$_SERVER['REQUEST_URI'].'"';
echo "\n";
echo 'Request ($_GET["request"]): "'.$_GET['request'].'"';
echo "\n";
echo 'd="'.$_GET['d'].'"';
echo "\n";
echo 'e="'.$_GET['e'].'"';
echo "\n";
?>
If I give it some URLs, they produce the corresponding outputs:
- mysite.com/a/b/c?d=1&e=2&request=3
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=1&e=2&request=3"
Request ($_GET["request"]): "3"
d="1"
e="2" - mysite.com/a/b/c?d=3&e=4
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=3&e=4"
Request ($_GET["request"]): "a/b/c"
d="3"
e="4"
$_SERVER["REQUEST_URI"] includes everything after mysite.com including the raw query string, and $_GET["request"] will not return the requested URL minus the query string if there is a key named request .
I could parse the value of $_SERVER["REQUEST_URI"] myself, but I'd like to use built-in functionality before coding around the problem.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d
Now I can Google this value and find all my Code Project posts!
|
|
|
|
|
$_SERVER["QUERY_STRING"] will give you the query string. (I forget if it includes the ? or not.) Picking off everything prior to the first ? (i.e. the URL part) isn't too hard.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Interestingly enough, I get all the pieces of the request neatly delimited by ampersands.
mysite.com/a/b/c?d=1&e=2&request=3
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=1&e=2&request=3"
Request ($_GET["request"]): "3"
Request ($_SERVER["QUERY_STRING"]): "request=index.php&request=a/b/c&d=1&e=2&request=3"
d="1"
e="2"
mysite.com/a/b/c?d=1&e=2&request=%26+%3F
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=1&e=2&request=%26+%3F"
Request ($_GET["request"]): "& ?"
Request ($_SERVER["QUERY_STRING"]): "request=index.php&request=a/b/c&d=1&e=2&request=%26+%3F"
d="1"
e="2"
Although the key-value pairs remain encoded, I guess it's still better to just use explode to get the key-value pairs first and then explode the resulting items to get the keys and values.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d
Now I can Google this value and find all my Code Project posts!
|
|
|
|
|
I did some testing, and it appears that certain values in the query can replace $1 in .htaccess with just 406.shtml or 406_shtml. mysite.com/a/b/c?d=1&e=2&%85 will cause this problem. It looks like I will have to parse the contents of $_SERVER['REQUEST_URI'] within the script if I want to handle all the cases without fail.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d
Now I can Google this value and find all my Code Project posts!
|
|
|
|
|
I have to analyze a system written in php. I am a .NET programmer. I will be emulating the php system. I have been given a tar dump of the directory. After decompression I need to find the starting php script. What should I be looking for? I have many php scripts, but it feels like a haystack. Can someone tell me what the starting needle name should be??
Thanks in advance... Chuck..
|
|
|
|
|
the default page in a directory normally is called index.php
|
|
|
|
|
Luc, Nice article. The problem is not recognising the PHP code or being able to read the code.
The problem is that I have several hundred PHP files. Which one is the first? That starts the app running. From there I and untangle the ball of string I have for years. Where is the beginning?
|
|
|
|
|
Do all PHP programs start with "main.php" or "index.php" or "default.php"?
|
|
|
|
|
No. In a web application, the default file in a folder is index.php, that is what gets served to a client when accessed by a browser.
You can create any filename.php you like and execute it locally by using a command line that fits your PHP platform and refers to the source file.
And there are ways to compile a bunch of PHP files into a single EXE, haven't done that yet.
|
|
|
|
|