tag:blogger.com,1999:blog-68942918419271173712024-03-12T22:52:23.693-07:00Sharing Problems of Practical ProgrammingAvi's blogAvi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-6894291841927117371.post-82266342392297686082013-04-12T13:57:00.001-07:002013-04-12T14:26:48.068-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h1 class="pagetitle" id="title-heading" style="background-color: white; font-family: Helvetica, Arial, sans-serif; font-size: 18pt; line-height: 1em; margin: 10px 0px 0.3em; padding: 0px; width: 1238px;">
<span id="title-text"><a href="http://174.129.202.195/confluence/pages/viewpage.action?pageId=1802290" style="color: black; text-decoration: none;">Laravel- W</a>orking with namespace</span></h1>
<div>
<br />
Starting with Laravel, soon had found that there is a lac of documentation. As a beginner, got a bunch of issues while starting with a modular <span style="color: #134f5c;"><span style="background-color: #9fc5e8;">Namespaced</span><span style="background-color: #9fc5e8;"> </span></span> approach for my project.<br />
<br />
<strike> Dont SKIP</strike> any paragraph of this doc, else one can get nasty issues.</div>
<div>
<h5 style="background-color: white; font-family: Helvetica, Arial, sans-serif; font-size: 1.1em; margin: 1em 0px 0.1em; padding: 0px;">
<ins>Creating a new module, with namespace</ins></h5>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<b>Step 1: Namespaced directory structure</b></div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
In our Laravel projects, we will <em>separate each features/modules, with separate namespaces</em>. But Laravel's Autoloader class makes a difference, with the way- traditional PHP namespace works.</div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
In Laravel, namespace works like JAVA, <em>we have to <u>create a directory same as namespace</u></em> & keep those files for that namespace under it.</div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<br /></div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<b>Namespace is applicable only for Models & Views. The Controllers cant be namespaced</b></div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
For e.g- if we create a Ratings module in our project with 'rating' namespace, then the directory structure will be-</div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
- application/models/<u>rating</u>/ratingmodel.php</div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
- application/models/<u>rating</u>/ratingview.php</div>
<div style="background-image: none; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<div style="background-color: white; color: #333333;">
- application/controllers/ratings.php // no namespace for controller</div>
<div style="background-color: white; color: #333333;">
<br /></div>
<span style="background-color: white; color: #333333;"> *We need to add </span><span style="background-color: #cfe2f3; color: #b6d7a8;"> </span><span style="font-family: 'Courier New', Courier, monospace; line-height: 1.3;"><span style="background-color: #cfe2f3;"><span style="color: #674ea7;">namespace rating;</span> </span><span style="background-color: white; color: #333333;"> at the very TOP of these namespaced files- </span></span><span style="background-color: white; color: #333333;">ratingmodel.php & </span><span style="background-color: white; color: #333333;">ratingview.php</span></div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<br /></div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<b>Step 3: Calling the namespaced model, views from CONTROLLER</b></div>
<div style="background-color: white; background-image: none; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<b><br /></b>once all the namespacing done- we can call the namespaced classes from controllers like this way</div>
<div style="background-color: white; background-image: none; margin-bottom: 10px; margin-top: 10px; padding: 0px;">
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px;">
-<u> nameSpace\Class- name. // Else the class will not be found</u></div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px;">
</div>
<pre><?php
class Ratings_Controller extends Base_Controller {
public function action_getRatings()
{
.......
//set the entity of Ratings Type
$objRatingsModel = new rating\Ratingsmodel();
// namespace\ClassName, else the class will not be found
</pre>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px;">
</div>
<b style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; white-space: normal;"><br /></b>
<b style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; white-space: normal;">Step 4: Calling the Laravel default classes from namespaced files</b>
<span style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; white-space: normal;">We can call the default Laravel functionalities( like- Validator::make(), DB::raw() ) from namespaced files, <u>by adding a back-slash(\) before</u> the class- to indicate they are from root-level namespace</span>
<span style="color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.328125px; white-space: normal;">For e.g-</span>
<br />
in rating/ratingmodel.php, </div>
<pre><?php
namespace rating;
class RatingModel{
public static function validateAndStoreInput($input)
{
// Validate the Ratings instance...
$rules = array(
'type' => 'required|alpha',
'id' => 'required|numeric|min:1'
);
$validation = \Validator::make($ratings->input, $rules);
// added a back-slash, else the class will not be found
....
}
....
}
</pre>
- thats all. Please comment if someone has any query or confusion.
Thanks.
</div>
</div>
Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com0tag:blogger.com,1999:blog-6894291841927117371.post-81146303507401547702012-08-08T08:50:00.000-07:002012-08-08T08:57:44.758-07:00Triggering an Asynchronous Process from PHP, Without Waiting to Complete<h3>Triggering an Asynchronous Process from PHP, Without Waiting to Complete</h3>
<p/>
Sometimes, we need to send a large amount of emails, sms or pushnotification from current script & the current page waits until al the stuffs are done.
<p/>
To, overcome this thing, we can simply <b>trigger a new process asynchronously and pass parameters to it, without making any wait</b> conditions. The process will start and take its time to complete, without affecting the parent script.
<p/>
we can use <a href="http://php.net/manual/en/function.exec.php"><b>exec()</b></a> or <a href="http://www.php.net/manual/en/function.system.php"><b>system()</b></a> function for that. The difference is System() also prints the output.
<br/>
Structure-
exec('PATH/TO/PHP PATH/TO/FILE.PHP');
<p/>
1. Here is a sample command to call another script from current file <b>as a separate process</b>-
<pre>
exec('/usr/bin/php5 /var/www/vhosts/mysite.com/httpdocs/PROCESS/processScript.php');
</pre>
<p/><p/>
2. Doing the above will start the script as a new process, <b>but the parent script will still wait</b> - this process to complete. To overcome that we will modify our command to this-
<pre>
exec('/usr/bin/php5 /var/www/vhosts/mysite.com/httpdocs/PROCESS/processScript.php > /dev/null 2>&1 &');
</pre>
<p/><p/>
3. Now, the process will execute, without keeping the parent to wait.
But, we surely <b>need to pass parameters to the process Script</b>. That will be simply accomplished using <a href="http://php.net/manual/en/reserved.variables.argv.php"><b>$argv</b></a>. <b>$argv</b> returns an array of arguments passed to script.
<p/>
In this example, we will<b> pass a parameter: 15 to the processScript.php</b>-
<pre>
exec('/usr/bin/php5 /var/www/vhosts/mysite.com/httpdocs/PROCESS/processScript.php 15 > /dev/null 2>&1 &');
</pre>
<p/>
- we are done.
<br/>
- <b>In processScript.php</b>, we will <b>get the parameter: 15</b> by-
<pre>
$paramID = $argv[1]; //$argv[0] is always the name that was used to run the script
</pre>
<p/><p/><p/>
- and that's all- we need to run a new PHP process. Please post a comment if you have any query or if you like the post.Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com5tag:blogger.com,1999:blog-6894291841927117371.post-18429218921935190302012-07-14T02:25:00.001-07:002012-07-14T02:25:53.437-07:00<h3>Android key hash for Facebook App</h3>
<br/>
Its pretty confusing to get a Key hash value for creating Facebook Apps for Android.
<p>
Here are the detailed steps for doing that-
</p>
<b>1.</b> We need to download <a href="http://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8k_WIN32.zip"><b>openssl</b></a> from Google code (<i>64 bit users</i> must download <a href="http://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8e_X64.zip&can=2&q="><b>openssl-0.9.8e X64</b></a>, not the latest version)
<br/><br/>
<b>2.</b> Extract it.
<br/>
<b>create a folder</b>- OpenSSL in C:/ and copy the extracted code here.
<br/><br/>
<b>3.</b> Detect <b>debug.keystore</b> file path.
<br/>If we can't find one, then lets do a <b>search in C:/</b> and we will use the Path in the command in next step.
<br/><br/>
<b>4.</b> Detect <b>keytool.exe path</b> and <i>go to that dir/</i> in command prompt and run this command in 1 line-
<pre>
> keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
</pre>
<br/>
Now, it will ask for password, put <b>android</b>
<br/>
That's all. It will return a key-hash.
<p>
Please post a comment, in case of any issue.Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com46tag:blogger.com,1999:blog-6894291841927117371.post-17714953113619952392012-07-14T01:59:00.001-07:002012-07-14T02:05:54.128-07:00<h3>Importing a deliminator-ed .txt or .csv file to MySQL DB, in PHP, directly from web form</h3>
<br/>
Its a common & handy thing <b>to import data</b>, directly into database- by a Website Admin user. Its much more efficient process for the Admin to insert data into table. Else- its kinda boring and irritating procedure to insert into table from 'Add User Form' or Phpmyadmin or whatever.
<b>Import from File MySQL Sample Command</b>
<pre>
LOAD DATA LOCAL INFILE 'from_import_file'
REPLACE INTO TABLE `table_name`
FIELDS TERMINATED BY '||'
LINES TERMINATED BY '\n' STARTING BY ''
</pre>
<p>
<b>Details from Scratch<i></i></b>
</p>
At very first, we'll take the file from the user, using simple form. Then we'll use <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html">LOAD DATA INFILE</a> to load into DB. Here is the code snippet-
<br/><br/>
<b>1.</b> <b>Create a Temporary table</b> which will have same field number as the imported DB file. For e.g-
<b>importUsers.txt</b> content( file to be imported- with deliminated string || )
<pre>
John Doe||user_id_123||The XYZ Company||Chicago
Mike Blinov||user_id_140||The ABC Company||New York
Austin Steven||user_457||WWE Tech LTD||Los Angeles
</pre>
<b>2.</b> Then create the <b>temporary table</b> with exact 4 columns-
<pre>
CREATE TABLE IF NOT EXISTS `users_temp` (
`name` varchar(50) NOT NULL,
`userId` varchar(50) NOT NULL,
`company` varchar(50) NOT NULL,
`city` varchar(50) NOT NULL
)
</pre>
<b>3.</b> Have an <b>HTML Form</b>
<pre>
<form enctype="multipart/form-data" action="" method="post" >
<label for="file_upload">Import Users</label>
<input type="file" name="file_upload" id="file_upload" />
<br/>
<input type="submit" value="Import" />
</form>
</pre>
<b>4.</b> On Submit Form PHP Code, upload the file with a unique name (This name is going to be used in the LOAD DATA Query) & getting the path of the uploaded file- from root
<pre>
if (!empty($_FILES))
{
$tempFile = $_FILES['file_upload']['tmp_name'];
// Validate the file type
$fileTypes = array('txt','csv','CSV'); // Valid File Extensions
$fileParts = pathinfo($_FILES['file_upload']['name']);
if (in_array($fileParts['extension'],$fileTypes))
{
//ploading with a unique name
$uploadedFileName = 'import_users_'.time().'_'.rand(100,999999).'.'.$fileParts['extension'];
$targetFile = 'ImportUser/' . $uploadedFileName;
//File Uploaded
move_uploaded_file($tempFile,$targetFile);
// Getting the Full Path
$fullPath = $_SERVER['SCRIPT_FILENAME'];
$pathParts = pathinfo($fullPath);
$pathToCurFile = $pathParts['dirname'];
// Getting the Full path of uploaded file- FROM ROOT
$uploadedFilepath = $pathToCurFile.'/'.$targetFile;
// Function defined later
$result = importUsers($uploadedFilepath);
}
else
{
//Error
echo 'Invalid file type. Please choose .txt or .csv file.';
}
}
else
{
//Error
echo 'Please upload a user list file.';
}
</pre>
<b>5.</b> Mysql Commned for import the file
<pre>
function importUsers($filePathFromRoot)
{
$sql = "LOAD DATA LOCAL INFILE '".$filePathFromRoot."'
REPLACE
INTO TABLE `users_temp`
FIELDS TERMINATED BY '||'
LINES TERMINATED BY '\n' STARTING BY ''";
$res = mysql_query($sql) or die ("Import Error");
}
</pre>
<b>6.</b> Now after a successful import every-time, we can read from this temporary table and populate our actual table & then make this temporary table empty.
<br/>
- thats all.
<br/>
Please comment in case of any issue.Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com0tag:blogger.com,1999:blog-6894291841927117371.post-29738608736089120992011-04-18T22:55:00.000-07:002012-07-12T03:18:06.562-07:00<h3>CURL POSTING ISSUES</h3>
In case of, developing a Facebook App, we need to first download the FB Class file (get the download links here- http://developers.facebook.com/docs/sdks/ or from here- https://github.com/facebook/php-sdk/) and need to do all work with its member functions.
The First common issue is getting CURL exceptions while Posting in the wall. We can track the CURL error and fix that issue.
There is another issue regarding CURL SSL certificate. We can simply turn off the CURL SSL Varifier.
Here are the code changes-
1. Download PHP SDK from-
https://github.com/facebook/php-sdk/
2. We need to turn-off the SSL Varification
Search for the array-
<pre>
public static $CURL_OPTS = array(
</pre>
and add another variable/ CURL-Property into it-
<pre>
CURLOPT_SSL_VERIFYPEER => false
</pre>
So, Finally the block will look like-
<pre>
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-2.0',
CURLOPT_SSL_VERIFYPEER => false
);
</pre>
3. For the CURL Error 77 (common while Posting through IE)
Search for this line-
<pre>
if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
</pre>
and simply modify this to-
<pre>
if (curl_errno($ch) == 60 || curl_errno($ch) == 77) { // CURLE_SSL_CACERT
</pre>
- it will escape the 77 Error as well.
- and we are done.Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com0tag:blogger.com,1999:blog-6894291841927117371.post-39562754394496247602011-03-21T21:25:00.000-07:002011-03-21T23:09:46.621-07:00Trick to post Code-Snippets in your BlogFrom last Few days, I was searching for a solution to post code, properly designed- obviously <span style="font-weight: bold;">for free blogs</span>. Because, currently its a headache to post code in blog as-it-is I want to post. Found some nice tricks. But, some of them needs registered blog-site[ should have FTP-Access, to upload files].<br />Also, got some template editing tricks, but they were not much good. So, i edited some css snippets, which is now working nicely [ that is currently used in this blog-post].<br />There are 4 steps to follow-<br /><br /><span style="font-weight: bold;">1.</span><br />Enter in your Blog admin and go to Design >> Edit HTML a<br /><br /><span style="font-weight: bold;">2.</span><br />Come to the end-of-head-section<br />OR<br />Simply search(ctrl+F) for this code ""<br /><br />Now our new code will go here -<span style="font-weight: bold;"><span style="font-weight: bold;"><br /><br /></span> </span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDZgePDdvEjdn7xZES5aoRyLXZNOHHp8eOLHPZpQJ8V7VIcpf-l62OMspiXuP56DqZPzVa8vYmph900tZJrCrt0C89xBdftM-K4VF-Dw-5841YWQtAriZ3uA_8fEEzz0LpIgoN5Q3jnmYP/s1600/3.+post_code_in_blogger_TRICK.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 420px; height: 300px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDZgePDdvEjdn7xZES5aoRyLXZNOHHp8eOLHPZpQJ8V7VIcpf-l62OMspiXuP56DqZPzVa8vYmph900tZJrCrt0C89xBdftM-K4VF-Dw-5841YWQtAriZ3uA_8fEEzz0LpIgoN5Q3jnmYP/s320/3.+post_code_in_blogger_TRICK.jpg" alt="" id="BLOGGER_PHOTO_ID_5586772513083434210" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style="font-weight: bold;"></span><br /><br /><span style="font-weight: bold;">3.</span><br />Now paste the below code here-<br /><br /><pre><br />pre, code<br />{<br />background:#efefef;<br />border:1px solid #A6B0BF;<br />font-size:100%;<br />line-height:130%;<br />overflow:auto;<br />padding:5px;<br />color:#000000 }<br />pre:hover {<br />border:1px solid #efefef;<br />}<br /><br />.clear { clear:both;<br />overflow:hidden;<br />}<br />pre .comment_in_code, code .comment_in_code<br />{<br />color:#999999;<br />}<br /></pre><br />and then Save your changes.<br /><br /><span style="font-weight: bold;">4.</span><br />Now, write a blog-post with code-snippets<br />Then parse it using-<br />http://www.blogcrowds.com/resources/parse_html.php<br />OR<br />http://www.elliotswan.com/postable/<br /><br />Then, find and wrap your codes such that-><br /><span style="font-weight: bold;"><pre> Your Post Code Snippet Here </pre></span><br />Or<br /><span style="font-weight: bold;"><code> Your Post Code Snippet Here</code></span><br /><br />And your comments within the Code goes here-<br /><span style="font-weight: bold;"><span class="comment_in_code"> //This is a comment within the code snippet. </span><br /></span><br /><br />- and thats all. The code-snippets and comments will look like-<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilJNMe8-YzUeBkyiTyhFp-c7G7FiBhgkrJgC4d4x3zuIzzw8VO3jlZKjbSK0U57irlAlavCSrLj5kGdQzQAku1GYBtZ5A5aMA62-Hnb1w5F04JnkLCwf-fVyxIDwZj4A3Grev9X0vQZZWU/s1600/3.+post_code_in_blogger_TRICK_2.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 480px; height: 169px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilJNMe8-YzUeBkyiTyhFp-c7G7FiBhgkrJgC4d4x3zuIzzw8VO3jlZKjbSK0U57irlAlavCSrLj5kGdQzQAku1GYBtZ5A5aMA62-Hnb1w5F04JnkLCwf-fVyxIDwZj4A3Grev9X0vQZZWU/s320/3.+post_code_in_blogger_TRICK_2.jpg" alt="" id="BLOGGER_PHOTO_ID_5586781026846716690" border="0" /></a>Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com0tag:blogger.com,1999:blog-6894291841927117371.post-635304630218499402011-03-11T14:01:00.000-08:002011-03-21T21:19:59.543-07:00treating a BLANK SPACE in REGULAR EXPRESSIONGot a problem while allowing a blank space in regular Expression, for service URL.<br /><br />-> so the solution is-<br />"S" (an uppercase 'S')<br /><br />So at last my regex pattern was like this in php-<br /><br /><pre><br />[a-z:A-Z;=;\\S]+/[0-9]+<br /><span class="comment_in_code">//Now it will allow case-insensitive any alphabet, any number</span><br /></pre>Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com1tag:blogger.com,1999:blog-6894291841927117371.post-68098222242814587702011-03-11T13:13:00.000-08:002011-03-21T21:14:23.711-07:00UPLOADIFY - problem while SETTING SESSION/ COOKIE - Alternate solutionToday I got a weird problem with UPLOADIFY while setting a cookie/ session with uploaded filename with current timestamp; from AJAXed uploadify.php.<br />I was trying to set that from uploadify.php so that I could get the filename to formSubmit.php.<br />but it was not working as there used to be a flash player issue (the flash player access the uploadify script as a new user and gets a new session).<br /><br />So, what I did is-<br /><br /><span style="font-weight: bold;">1.</span><br /><span style="font-weight: bold;">in form.php (also contains javascript)-</span><br /><br /><pre><br /><?php<br /><span class="comment_in_code">// setting a variable with current timestamp, to rename a file. <br/>[it will not affect on .gif/.png images]</span><br />$uploadedImg = time().'.jpg';<br />?><br /><br /><script type="text/javascript"><br />$(document).ready(function() {<br /> $('#file_upload').uploadify({<br /> 'uploader' : './uploadify/uploadify.swf',<br /> 'script' : './uploadify/uploadify.php',<br /> 'cancelImg' : './uploadify/cancel.png',<br /> 'folder' : './pics',<br /> 'auto' : true,<br /> 'scriptData' : {'imgName': '<?=$uploadedImg?>'},<br /> 'buttonText': 'Select Logo',<br /><br /> 'onAllComplete' : function(event,data) {<br /> $('#profile_pic_flag').val(1);<br /> }<br />});<br />});<br /></script><br /><br /><br /><form method="POST" action="formSubmit.php"><br /><br /><span class="comment_in_code"><!-- UPLOADIFY input element --></span><br /> <input id="file_upload" name="file_upload" type="file" /><br /><br /><br /><br /> <span class="comment_in_code"><!-- input element to get the Picture name--></span><br /> <input type="hidden" name="profile_pic" id="profile_pic" value="<?=$uploadedImg?>" /><br /><br /> <span class="comment_in_code"><!-- input element to Check if an imege is<br/> uploaded or not(value set by UPLOADIFY onAllComplete event),<br/> [this element is more efficient while Editing forms]--></span><br /> <input type="hidden" name="profile_pic_flag" id="profile_pic_flag" value="0" /><br /><br /></form><br /><br /></pre><br /><br /><br /><span style="font-weight: bold;">2.</span><br /><span style="font-weight: bold;">in AJAXed uploadify.php</span><br /><br />replace this part-<br /><br /><pre><br />$tempFile = $_FILES['Filedata']['tmp_name'];<br />$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';<br />$upFileName = $_REQUEST['imgName'];<br />$targetFile = str_replace('//','/',$targetPath) . $upFileName;<br /><br /><span class="comment_in_code">// uploading the file with the 'imgName', which was set by form.php</span><br /><span class="comment_in_code">// and picture uploaded easily</span><br /></pre><br /><br /><span style="font-weight: bold;">3.</span><br /><span style="font-weight: bold;">in formSubmit.php</span><br /><br /><pre><br />if(isset($_POST['profile_pic']) && $_POST['profile_pic'] && $_POST['profile_pic_flag'] )<br />{<br /> $profilePic = './pics/'.$_POST['profile_pic'];<br /> <span class="comment_in_code">// Then storing the $profilePic in Database.</span><br />}<br /></pre><br /><br />- And all are done.Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com2tag:blogger.com,1999:blog-6894291841927117371.post-23756063026771434422011-02-04T04:45:00.000-08:002011-02-04T04:57:54.062-08:00INTROJust treating this blog- as a notebook and noting the issues I got from- very first day of programming.<br /><br /> Am planning to post the head-cracking errors to silly mistakes or steps to accomplish a common task.<br /><br /> My area of programming(& also designing) till date are-<br /><ul><li>HTML</li><li>CSS</li><li>JavaScript</li><li>JQuery<br /></li><li>PHP</li><li>Web Services</li><li>MySQL<br /></li><li>Adobe Photoshop</li></ul>& also have a little experience(which is growing++) in<br /><ul><li>ASP.NET C#</li><li>Android<br /></li></ul>Avi Chttp://www.blogger.com/profile/01535218094082029211noreply@blogger.com0