|
Narr, it works. Now I believe reading the file requires
unpack()
function.
I tried to read about this function but I get confused with the format that is to be specified to it but I am trying to understand it. Thanks a lot.
|
|
|
|
|
Hi all. I am a beginner in php programming. Given a web page with links, I would like to know how I can send the selected link to a php script so that it will return the appropriate page requested. I don't if this can be done in an anchor ( <a> ) tag. Please help.
|
|
|
|
|
Ok I'm not quite sure what you mean. A link on a page already loads a file from the webserver (eg: <a href="http://www.somesite.com/mypage.php">MyLink</a> ). The link I gave in the sample would load mypage.php from the webserver.
If you mean you wish to use one single entry point (eg: index.php) for all page requests then you could do this using the querystring. Just set a parameter with the page you want to load and put the entire url in the A tag.
So in the second case you would end up with something like:
<a href="http://www.somesite.com/index.php?page=mypage">MyLink</a>
|
|
|
|
|
Ok been working on this for about 2 hours and I'm officially stuck.
What I'm trying to do is bild a calendar (got that part working how I want) where I can change the month.
I have the following code:
function startTable2($currentMonth,$currentYear) {
$month = date("F", mktime(0,0,0, date($currentMonth), date("t"), date($currentYear)));
echo "<table border=1 align=\"center\">";
echo "<form action=\"Calendar2.php\" method=\"post\">";
echo "<tr>";
echo "<td align=\"left\"><input type=\"submit\" name=\"previous\" id=\"previous\" value=\"Previous Month\" />";
if ($currentMonth == 1) {
$currentYear = $currentYear - 1;
$currentMonth = 12;
}
else
{
$currentMonth = date("m", mktime(0,0,0, date($currentMonth)-1, date("1"), date($currentYear)));
}
echo "<input type=\"hidden\" name=\"month\" id=\"month\" value=$currentMonth /></td>";
echo "<input type=\"hidden\" name=\"year\" id=\"year\" value=$currentYear /></td>";
echo "<input type=\"hidden\" name=\"day\" id=\"day\" value=\"01\" /></td>";
echo "</form>";
echo "<td colspan=5 align=center>$month $currentYear</td>";
echo "<form action=\"Calendar3.php\" method=\"post\">";
if ($currentMonth == 12) {
$currentYear = $currentYear + 1;
$currentMonth = 1;
}
else
{
$currentMonth = date("m", mktime(0,0,0, date($currentMonth)+1, date("1"), date($currentYear)));
}
echo "<td align=\"right\"><input type=\"submit\" name=\"next\" id=\"next\" value=\"Next Month\" />";
echo "<input type=\"hidden\" name=\"month1\" id=\"month1\" value=$currentMonth /></td>";
echo "<input type=\"hidden\" name=\"year1\" id=\"year1\" value=$currentYear /></td>";
echo "<input type=\"hidden\" name=\"day1\" id=\"day1\" value=\"01\" /></td>";
echo "</td></form></tr>";
echo "<tr><td align=center>Sunday</td><td align=center>Monday</td><td align=center>Tuesday</td><td align=center>Wednesday</td><td align=center>Thursday</td><td align=center>Friday</td><td align=center>Saturday</td></tr>";
}
As of now the "previous" works for every other month (i.e. December, October, August... etc) and the "next" is not working at all (blank screen). I've tried different methods for getting the new date and month but with no luck. Any help is greatly appreciated.
Thank You!
|
|
|
|
|
I've made some code changes and the next no longer comes up blank, it's not right but it's not blank... I also tried to make it more readable.
function startTable2($currentMonth,$currentYear) {
$month = date("F", mktime(0,0,0, date($currentMonth), date("t"), date($currentYear)));
$year = $currentYear;
echo "<table border=1 align=\"center\">";
echo "<tr>";
echo "<td align=\"left\">";
echo "<form action=\"Calendar2.php\" method=\"post\">";
echo "<input type=\"submit\" name=\"previous\" id=\"previous\" value=\"Previous Month\" />";
if ($currentMonth == 1) {
$currentYear = $currentYear - 1;
$currentMonth = 12;
}
else
{
$currentMonth = date("m", mktime(0,0,0, date($currentMonth)-1, date("1"), date($currentYear)));
}
echo "<input type=\"hidden\" name=\"month\" id=\"month\" value=$currentMonth />";
echo "<input type=\"hidden\" name=\"year\" id=\"year\" value=$currentYear />";
echo "<input type=\"hidden\" name=\"day\" id=\"day\" value=\"01\" />";
echo "</form>";
echo "</td>";
echo "<td colspan=5 align=center>$month $year";
echo "</td>";
echo "<td align=\"right\">";
echo "<form action=\"Calendar3.php\" method=\"post\">";
echo "<input type=\"submit\" name=\"next\" id=\"next\" value=\"Next Month\" />";
if ($currentMonth == 12) {
$currentYear = $currentYear + 1;
}
else
{
$currentMonth = $currentMonth + 1;
}
echo "<input type=\"hidden\" name=\"month1\" id=\"month1\" value=$currentMonth />";
echo "<input type=\"hidden\" name=\"year1\" id=\"year1\" value=$currentYear />";
echo "<input type=\"hidden\" name=\"day1\" id=\"day1\" value=\"01\" />";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=center>Sunday</td><td align=center>Monday</td><td align=center>Tuesday</td><td align=center>Wednesday</td><td align=center>Thursday</td><td align=center>Friday</td><td align=center>Saturday</td>";
echo "</tr>";
}
hope that helps a little.
|
|
|
|
|
|
For your information, I doubt anyone on this forum is gonna click a link for a file from a person they don't know.
Anyway, what is preventing you from opening the file? Is it encrypted?
Even Notepad* is able to open PHP files:
- Right-click on the file, point to "Open with..."
- Select "Notepad" from the list (if it is not visible, click "Choose standard application" and find Notepad in the list)
If that doesn't solve your issue, you're going to have to elaborate a bit.
*Instead of Notepad, I recommend Notepad++[^] which is a great text editor with line numbering, syntax coloring and a lot of other neat features.
|
|
|
|
|
<?php
$to = "someone@domain.com";
$subject = "Test";
$message = "Hello";
$from = "someonelse@domain.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
as far as i understand this is a valid mail function, but on the server it won't send anything to anyone, even my hotmail account .....What am i doing wrong ? this is all the code i have for this particular function so that i can test if it will work to submit feedback results to another mailbox....
(obviously the mail $to email is the one i am only using for this forum post )
i have asked the server support team and they say that this should work?
any ideas what else to try ...
|
|
|
|
|
I have a similar setup and I don't see anything wrong with what you have, so unless I'm blind it looks like it should indeed work. In fact what you have is almost identical to the php documentation.
Are you sure the server email system is working and has the correct settings in the php.ini file?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
turns out the server people lied to me, thanks for your help anyway .... any idea what i could do to get an SMTP?
could i send the information to another website easily or ?
|
|
|
|
|
|
look for class.smtp.php from Chris Ryan.
that s good one for start to send mails using your smtp server.
|
|
|
|
|
class SafeEmail<br />
30 {<br />
31 function create($user, $host, $suffix)<br />
32 {<br />
33 $at = "@";<br />
34 $dot = ".";<br />
35 <br />
36 $start = $user . at . $host;<br />
37 $end = $dot . $suffix;<br />
38 $address = $start . end<br />
39 <br />
40 return $address;<br />
41 }<br />
42 <br />
43 $se = new SafeEmail();<br />
44 $se->create($user, $host, $suffix);<br />
45 }
More php email scripts listed on the page!
|
|
|
|
|
I have few urls like
http://www.mydomain.com/statecode1-folder1
http://www.mydomain.com/statecode2-folder1
I want to redirect it to http://www.mydomain.com/folder1/ page but I want to show on browser url the original urls likes
http://www.mydomain.com/statecode1-folder1
http://www.mydomain.com/statecode2-folder1
Please note that I do not have folders statecode1-folder1 and statecode2-folder1
Currently I use the below .htaccess which redirects but it changes the address bar
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/ statecode1-folder1 $
RewriteRule ^(.+) / folder1 [L]
RewriteCond %{REQUEST_URI} ^/ statecode2-folder1 $
RewriteRule ^(.+) / folder1 [L]
Thanks in Advance
Regards
Salman Ansari
|
|
|
|
|
Why the below code doesn't upload file to http://xyz.com/uvw/upload_data.php[^] automatically ?
I get error = uploaded file is either missing, empty or was not uploaded via the POST method
But am sure uploading file is not missing or empty as i have echo it and i think i am uploading via post method ?
function datapost($URLServer,$postdata)
{
$agent = "Mozilla/5.0";
$cURL_Session = curl_init();
curl_setopt($cURL_Session, CURLOPT_URL,$URLServer);
curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent);
curl_setopt($cURL_Session, CURLOPT_POST, 1);
curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($cURL_Session);
return $result;
}
$postdata = array();
$postdata['Id'] = '12340';
$postdata['profileName'] = 'tsunami';
$postdata['file'] = file_get_contents('http://www.abc.co.uk/def/ghi.csv');
$postdata['submit'] = urlencode('submit');
$source= datapost("http://xyz.com/uvw/upload_data.php",$postdata);
Any suggestion devs ??
|
|
|
|
|
Hi,
You need to set CURLOPT_HTTPGET to false explicitly - the PHP documentation doesn't make this clear.
curl_setopt($cURL_Session, CURLOPT_HTTPGET, FALSE);
Niall
|
|
|
|
|
Thanks,
I added the line you said but still getting the same error ..
Anything else i can add/edit to make it working ?
Cheers
|
|
|
|
|
No - that works on my system, as long as the CSV file isn't too big. (OK with 150k, not with 30M)
This is the version of your code I tried out.
<?php
function datapost($URLServer,$postdata)
{
$agent = "Mozilla/5.0";
$cURL_Session = curl_init();
curl_setopt($cURL_Session, CURLOPT_URL,$URLServer);
curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent);
curl_setopt($cURL_Session, CURLOPT_HTTPGET, FALSE);
curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($cURL_Session);
return $result;
}
$postdata = array();
$postdata['Id'] = '12340';
$postdata['profileName'] = 'tsunami';
$postdata['file'] = file_get_contents('http://localhost/tmp/test.csv');
$postdata['submit'] = urlencode('submit');
$source= datapost("http://localhost/tmp/posthere.php",$postdata);
echo $source;
?>
My test posthere.php is
<?php
foreach($_POST as $k=>$v)
{
echo "$k => ".strlen($v)."<br/>";
}
?>
|
|
|
|
|
Niall Barr wrote: (OK with 150k, not with 30M)
Initially i thought this could be the case as i was uploading around 12mb csv but then i tried with just 4kb but still getting the same error.
I don't really understand what could be the problem - the uploading works fine if i try using normal html form submit but as we don't want to manually browse the file - we decided to go this route and it's not working.. What a pain.
On the other hand why do you say it will not work for size in MB ? Is there any other auto upload way for such big files ?
|
|
|
|
|
I think the only issue was the amount of memory available to PHP on my dev box. I tried with a file that was too big for it.
Are you able to get the other post data transferred if you comment out the file_get_contents line?
Niall
|
|
|
|
|
Niall Barr wrote: Are you able to get the other post data transferred if you comment out the file_get_contents line?
I can't test that as it's some external company site where we have to upload our data so that they can do what they are suppose to do with the data.
Well i use below code as initial request - so they receive the post data and they send us back id which we need to send along with the file -
function datapost($URLServer,$postdata)
{
$agent = "Mozilla/5.0";
$cURL_Session = curl_init();
curl_setopt($cURL_Session, CURLOPT_URL,$URLServer);
curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent);
curl_setopt($cURL_Session, CURLOPT_POST, 1);
curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($cURL_Session);
return $result;
}
$postdata = array();
$postdata['profileName'] = 'tsunami';
$postdata['tName'] = 'abc';
$postdata['langCode'] = 'en_GB';
... etc
$source= datapost("http://xyz.com/uvw/upload_meta.php",$postdata);
</pre>
It using the same process - so am sure it's only file auto upload bit that's not working for us. As i said it works using normal html form submit.
|
|
|
|
|
It occured to me that it's likely that the site you're posting to expects an attached file rather than the file content in a post field called file...
If that's the case, then this code should work.
<?php
function datapost($URLServer,$postdata)
{
$agent = "Mozilla/5.0";
$cURL_Session = curl_init();
curl_setopt($cURL_Session, CURLOPT_URL,$URLServer);
curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent);
curl_setopt($cURL_Session, CURLOPT_POST, 1);
curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata);
$result = curl_exec($cURL_Session);
curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1);
return $result;
}
$postdata = array();
$postdata['Id'] = '12340';
$postdata['profileName'] = 'tsunami';
$tmpfile = tempnam(false,'tmp_');
$filedata = file_get_contents("http://localhost/tmp/test.csv");
file_put_contents($tmpfile, $filedata);
$postdata['file'] = "@$tmpfile";
$postdata['submit'] = urlencode('submit');
$source= datapost("http://localhost/tmp/posthere.php",$postdata);
unlink($tmpfile);
echo $source;
?>
|
|
|
|
|
great ... this worked like a charm
Thanks a ton.
|
|
|
|
|
Hi all,
All the while i use to develop PHP app from scratch. Now i thought using standard php framework will be good for better maintenance and support from my teammate. I wonder which PHP framework is good for enterprise application like ZOHO and which php framework is good for normal cms app.
Thanks
|
|
|
|
|
CakePHP is a rapid development PHP framework that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code.
Hopefully can help you!
Best regards!
Chiry.
|
|
|
|
|