PHP - Parse Json String And Sort
I need parse the JSON string below into an associative array, sort it by the 'age' field and output the sorted array as an HTML table. Here is what I have done so far but it just returns me 'Array':
Code: [Select] <?php $json='[{"name": "John","age": 23},{"name": "jim","age": 19},{"name": "jason","age": 34}]'; $array = json_decode( $json, true); function cmp( $a, $b){ if( !isset( $a['age']) && !isset( $b['age'])){ return 0; } if( !isset( $a['age'])){ return -1; } if( !isset( $b['age'])){ return 1; } if( $a['age'] == $b['age']){ return 0; } return (($a['age'] > $b['age']) ? 1 : -1); } usort( $array, 'cmp'); foreach ($array as $key => $value) { echo $key.":".$value."\n"; } ?> Similar TutorialsI'm trying the fetch some geocode data from mapquest. Google doesn't like me right now. I keep running into the query_limit. So I want to set a back up that will go into production when I get that error from the big G. I have my api key and I can put the string in a var. Code: [Select] $geocode = file_get_contents($url) I selected json as the output and when I echo $geocode... here is the first portion of the string....(I want lat & lng) Code: [Select] renderOptions({"results":[{"locations":[{"latLng":{"lng":-112.35984,"lat":34.58752},..... Now for the life of me, I can't do anything with it. I've tried json_decode() with the true argument there and not. Code: [Select] $output = json_decode($geocode, true); $output = json_decode($geocode); vardump($output) is NULL. So, I thought, well maybe I don't need to decode it, but I can't figure out how to parse it. I'm lost. This admittedly is my first attempt as trying to work with a jason object, but jeesh, it doesn't seem like it should be that hard. Can someone start me in the right direction? Hello
This may seem like a silly question but if you never ask you never know...
Lets say I json encode a php array. When I echo out the encoded json string into a JS variable it looks something like this in the resultant markup:
var arr = ["cow - Copy (10).jpg","cow - Copy (2).jpg"];So in this instance the string I've echoed out is equivalent to a JS array and I can use it straight away. My questions: 1) Is it valid to do what I've done above? 2) Since I can use the array right away is there any need to JSON.parse? 3) When would you use JSON.parse? Thanks, Drongo Hello Can you please show me how can i parse this JSON in PHP? {"status":"error","error":{"error_code":700,"error_message":"Recognition failed: you didn't send file via POST or file url as `url` param."},"requested_params":{"method":"recognize"}}
I need to setup a condition : If(status="error) than $errorcode=700 errormessage=Recognition failed: you didn't send file via POST or file url as `url` param errorMethod= "recognize" Hello, I am a novice with php and know close to nothing about JSON. I am using wordpress and have 2 calendar type plugins I want to work together. With one plugin the user inputs dates that they are booked. The other plugin is a date picker, the cool part is it allows you to black out dates using php before the date picker is built. So what I'm trying to do is get the data from what the user chose as booked, and not let a user on the front end pick any of the booked dates with the date picker. Hope that makes sense. The problem is the formatting of the data with the date booked plugin. This is what is in the field Code: [Select] a:1:{s:9:"calendars";a:1:{i:1;a:4:{s:12:"calendarName";s:21:"Availability Calendar";s:12:"calendarJson";s:59:"{"year2011":{"month12":{"day25":"booked","day6":"booked"}}}";s:11:"dateCreated";i:1324333825;s:12:"dateModified";i:1324333825;}}} I chose 2 dates to be booked in that example: dec 25 2011, and dec 6 2011. I have no idea how I would parse the above data into what I need. I don't really need the data from the other parts of the above code, just the dates. The others are field descriptions and etc. that wordpress uses. Incidentally, this is what the date picker setup would look like in the above senario: Code: [Select] $myCalendar->setSpecificDate(array("2011-12-06","2011-12-25"), 0, ''); Hello.
Server returns this json
{"status":1,"job_status":"READY","iterations":["Contig2","Contig75"],"accessions":["NP_001061702","NP_001068174"]}And i would like to print out in a textarea (using the above jQuery command) $('#info').val()something like this: Contig2 : NP_001061702 Contig75 : NP_001068174 Any idea on how to achieve this? Thanks! Hello.
I am new here.
I have a sligh problem, i saw a few results here which however did not lead to the desired result.
The problem is , i have this Json Response from a API:
Array ( [0] => Array ( [isoid] => 0 [omschrijving] => - leeg - ) [1] => Array ( [isoid] => 64 [omschrijving] => ArchLinux 2013.5 ) [2] => Array ( [isoid] => 75 [omschrijving] => AsteriskNOW 3.0.0 64b ) [3] => Array ( [isoid] => 67 [omschrijving] => CentOS 5.9 32b ) [4] => Array ( [isoid] => 2 [omschrijving] => CentOS 6.3 64b ) [5] => Array ( [isoid] => 96 [omschrijving] => CentOS 7.0 64b ) [6] => Array ( [isoid] => 4 [omschrijving] => Clear OS 5.2 64b ) [7] => Array ( [isoid] => 93 [omschrijving] => CloudLinux 6.4 ) [8] => Array ( [isoid] => 1 [omschrijving] => Debian GNU/Linux 6.0 / Squeeze 64b ) [9] => Array ( [isoid] => 79 [omschrijving] => Debian GNU/Linux 7.0 / Wheezy 32b ) [10] => Array ( [isoid] => 71 [omschrijving] => Debian GNU/Linux 7.0 / Wheezy 64b ) [11] => Array ( [isoid] => 63 [omschrijving] => Fedora 18 64b ) [12] => Array ( [isoid] => 82 [omschrijving] => FreeBSD 10 64b ) [13] => Array ( [isoid] => 77 [omschrijving] => FreeBSD 9.2 64b ) [14] => Array ( [isoid] => 10 [omschrijving] => FreePBX 5.211.65-12 ) [15] => Array ( [isoid] => 76 [omschrijving] => GParted Live CD ) [16] => Array ( [isoid] => 3 [omschrijving] => KVM Virtio drivers voor Windows ) [17] => Array ( [isoid] => 66 [omschrijving] => MailCleaner 2012v6 64b ) [18] => Array ( [isoid] => 68 [omschrijving] => Manjaro KDE 0.8.6 64b ) [19] => Array ( [isoid] => 78 [omschrijving] => Microsoft Windows 7 Pro 64b ) [20] => Array ( [isoid] => 69 [omschrijving] => Microsoft Windows Server 2003 EN ) [21] => Array ( [isoid] => 8 [omschrijving] => Microsoft Windows Server 2008R2 EN ) [22] => Array ( [isoid] => 7 [omschrijving] => Microsoft Windows Server 2008R2 NL ) [23] => Array ( [isoid] => 70 [omschrijving] => Microsoft Windows Server 2012 NL 64b ) [24] => Array ( [isoid] => 84 [omschrijving] => Microsoft Windows Server 2012R2 NL ) [25] => Array ( [isoid] => 83 [omschrijving] => NOC PS 1.0r11 ) [26] => Array ( [isoid] => 11 [omschrijving] => OpenBSD 5.2 ) [27] => Array ( [isoid] => 80 [omschrijving] => OpenBSD 5.4 ) [28] => Array ( [isoid] => 94 [omschrijving] => OpenBSD 5.5 64b ) [29] => Array ( [isoid] => 72 [omschrijving] => OpenSUSE 12.3 64b ) [30] => Array ( [isoid] => 95 [omschrijving] => Slackware 13.37 ) [31] => Array ( [isoid] => 12 [omschrijving] => System Rescue CD ) [32] => Array ( [isoid] => 18 [omschrijving] => Turnkey Appflower ) [33] => Array ( [isoid] => 19 [omschrijving] => Turnkey ASP.net/Apache ) [34] => Array ( [isoid] => 20 [omschrijving] => Turnkey Bugzilla ) [35] => Array ( [isoid] => 21 [omschrijving] => Turnkey CodeIgniter ) [36] => Array ( [isoid] => 22 [omschrijving] => Turnkey Django ) [37] => Array ( [isoid] => 23 [omschrijving] => Turnkey Dokuwiki ) [38] => Array ( [isoid] => 24 [omschrijving] => Turnkey DomainControler ) [39] => Array ( [isoid] => 25 [omschrijving] => Turnkey Drupal7 ) [40] => Array ( [isoid] => 26 [omschrijving] => Turnkey Fileserver ) [41] => Array ( [isoid] => 27 [omschrijving] => Turnkey Gallery ) [42] => Array ( [isoid] => 28 [omschrijving] => Turnkey Gitlab ) [43] => Array ( [isoid] => 15 [omschrijving] => Turnkey Google AppEngine Go ) [44] => Array ( [isoid] => 16 [omschrijving] => Turnkey Google AppEngine Java ) [45] => Array ( [isoid] => 17 [omschrijving] => Turnkey Google AppEngine Python ) [46] => Array ( [isoid] => 29 [omschrijving] => Turnkey IceScrum ) [47] => Array ( [isoid] => 30 [omschrijving] => Turnkey Joomla2.5 ) [48] => Array ( [isoid] => 31 [omschrijving] => Turnkey LAMP ) [49] => Array ( [isoid] => 32 [omschrijving] => Turnkey Lighttpd/PHP/FastCGI ) [50] => Array ( [isoid] => 33 [omschrijving] => Turnkey Magento ) [51] => Array ( [isoid] => 34 [omschrijving] => Turnkey Mediawiki ) [52] => Array ( [isoid] => 35 [omschrijving] => Turnkey MongoDB ) [53] => Array ( [isoid] => 36 [omschrijving] => Turnkey MySQL ) [54] => Array ( [isoid] => 37 [omschrijving] => Turnkey NGINX/PHP/FastCGI ) [55] => Array ( [isoid] => 38 [omschrijving] => Turnkey OpenLDAP ) [56] => Array ( [isoid] => 39 [omschrijving] => Turnkey OpenPhoto ) [57] => Array ( [isoid] => 40 [omschrijving] => Turnkey OSCommerce ) [58] => Array ( [isoid] => 41 [omschrijving] => Turnkey OTRS ) [59] => Array ( [isoid] => 42 [omschrijving] => Turnkey Owncloud ) [60] => Array ( [isoid] => 43 [omschrijving] => Turnkey PHPBB ) [61] => Array ( [isoid] => 44 [omschrijving] => Turnkey PHPList ) [62] => Array ( [isoid] => 45 [omschrijving] => Turnkey PHPNuke ) [63] => Array ( [isoid] => 46 [omschrijving] => Turnkey Postgresql ) [64] => Array ( [isoid] => 47 [omschrijving] => Turnkey Prestashop ) [65] => Array ( [isoid] => 48 [omschrijving] => Turnkey Rails ) [66] => Array ( [isoid] => 49 [omschrijving] => Turnkey Redmine ) [67] => Array ( [isoid] => 50 [omschrijving] => Turnkey SiTracker ) [68] => Array ( [isoid] => 51 [omschrijving] => Turnkey StatusNET ) [69] => Array ( [isoid] => 52 [omschrijving] => Turnkey SugarCRM ) [70] => Array ( [isoid] => 53 [omschrijving] => Turnkey Symfony ) [71] => Array ( [isoid] => 54 [omschrijving] => Turnkey Tomcat ) [72] => Array ( [isoid] => 55 [omschrijving] => Turnkey Tomcat/Apache ) [73] => Array ( [isoid] => 56 [omschrijving] => Turnkey TRAC ) [74] => Array ( [isoid] => 57 [omschrijving] => Turnkey TWiki ) [75] => Array ( [isoid] => 58 [omschrijving] => Turnkey Typo3 ) [76] => Array ( [isoid] => 59 [omschrijving] => Turnkey Wordpress ) [77] => Array ( [isoid] => 60 [omschrijving] => Turnkey Zencart ) [78] => Array ( [isoid] => 13 [omschrijving] => Ubuntu 10.04 32b ) [79] => Array ( [isoid] => 6 [omschrijving] => Ubuntu 10.04 64b ) [80] => Array ( [isoid] => 14 [omschrijving] => Ubuntu 12.04 32b ) [81] => Array ( [isoid] => 61 [omschrijving] => Ubuntu 12.04 64b ) [82] => Array ( [isoid] => 62 [omschrijving] => Ubuntu 12.10 64b ) [83] => Array ( [isoid] => 89 [omschrijving] => Ubuntu 14.04 LTS 64b ) [84] => Array ( [isoid] => 5 [omschrijving] => Windows Password Reset ) [85] => Array ( [isoid] => 81 [omschrijving] => Zen Loadbalancer 3.03 ) [86] => Array ( [isoid] => 74 [omschrijving] => Zentyal 3.2 ) )how would i go to fill it automatically in a option value like <option value='74'>Zentyal 3.2</option>Thank you in advance I got a response from an api in json. How do i echo out the account_name in string. Thanks as usual. The response is below...
{ "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } } "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } }
I have the following code and it always says it's a string! How do I make it see it as a json object? Code: [Select] <?php //We'll return a json object from post request if ( !empty( $_POST ) ) { $arr = array ('status'=>1,'message'=>'Some message'); echo json_encode($arr); } else { ?> <input type="button" value="submit" id="submit" /> <script type="text/javascript" src="/scripts/jquery-1.4.2.js"></script> <script> var submit = document.getElementById( "submit" ); submit.onclick = function() { $.post( "test.php", function(data) { /* * This always prints as: * {"status":1,"message":"Some message"} * string * Code: undefined * Message: undefined */ alert( data + "\n" + typeof( data ) + "\nCode: " + data.status + "\nMessage: " + data.message ); } ); } </script> <? } ?> What do I do to make it a json object? Hello to everyone Can someone help me on how to parse this CSV string? I do not know how to parse string using PHP.. #1# "4","+447980123456","+447781484145","","2009-07-08","10:38:15","hello "","" world","Orange" "5","+447980123456","+447781484146","","2009-07-08","10:38:55","hello world","Orange" This string can contain a much bigger data. I would like the result to be Originator : +447781484145, Date : 2009-07-07, Time : 10:38:15, Message : hello world Originator : +447781484146, Date : 2009-07-08, Time : 10:38:55, Message : hello world Please guys if anyone of you knows how to parse this string it will be much appreciated. Im nearing my deadline for my work and this thing is keeping me from finishing it.. Thanks in advance I have a $string with this structure "word-word2 something-SECONDPART". I want to divide it to $string1 and $string2 by separating with the last "-". The point is that "-" exists in the first part, and I just want to make the second string after the last "-" http://paste.ee/p/OhiWv
The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working.
<script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script> I have a list of pictures and I want to control the order. Here is the picture format: $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_1.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_2.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_3.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_4.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_5.jpg Notice the order 1.jpg, 2.jpg, etc.. Here is where I'm stuck... // begin stuck :) $orderPic = explode("_", $pic); foreach($orderPic as $rank){ echo "$rank"; // I need $rank to equal 1 then 2 then 3 ... } It would be nice actually if I could start the insert with number 2 because number one is always a screwy picture. I hope this makes sense / Thank for the help! Say you have a string that you know has two, and exactly two, periods in it, like this...
$string = "3.12.8"How can you grab the three different values that are separated by periods (in this case, 3, 12 and ? I was thinking use strpos to find the position of the first period, then could use that info to grab everything up to that position. But then I couldn't figure out how you would find the position of the SECOND period. And even if I could get the exact positions of the two periods, it seems like there should be an easier way to simply retrieve values separated by specific characters. Is there a specific function for this type of thing, or was my initial though correct with having to do it in two parts essentially (find positions of periods, then use that knowledge to get the values)? Thanks! Hi All i am wanting a column list like this http://extensions.joomla.org/extensions basically the database is set up as (id, category, parent) I want the parent to group the category section and list like the the joomla example in three columns search various threads throughout the internet but none seem to cover this entirely can any one please help????? hi all am new to this forum help me to overcome from this error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in D:\wamp\www\quiz1\quiz1.php on line 12 Code: [Select] <?php include("contentdb.php"); $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); if (!$submit) { echo "<form method=post action=$_SERVER['PHP_SELF']>"; echo "<table border=0>"; while ($row = mysql_fetch_array($display)) { $id = $row["id"]; $question = $row["question"]; $opt1 = $row["opt1"]; $opt2 = $row["opt2"]; $opt3 = $row["opt3"]; $answer = $row["answer"]; echo "<tr><td colspan=3><br><b>$question</b></td></tr>"; echo "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td></tr>"; } echo "</table>"; echo "<input type='submit' value='See how you did' name='submit'>"; echo "</form>"; } elseif ($submit) { $score = 0; $total = mysql_num_rows($display); while ($result = mysql_fetch_array($display)) { $answer = $result["answer"]; $q = $result["q"]; if ($$q == $answer) { $score++; } } echo "<p align=center><b>You scored $score out of $total</b></p>"; echo "<p>"; if ($score == $total) { echo "Congratulations! You got every question right!"; } elseif ($score/$total < 0.34) { echo "Oh dear. Not the best score, but don't worry, it's only a quiz."; } elseif ($score/$total > 0.67) { echo "Well done! You certainly know your stuff."; } else { echo "Not bad - but there were a few that caught you out!"; } echo "</p>"; echo "<p>Here are the answers:"; echo "<table border=0>"; $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); while ($row = mysql_fetch_array($display)) { $question = $row["question"]; $answer = $row["answer"]; $q = $row["q"]; echo "<tr><td><br>$question</td></tr>"; if ($$q == $answer) { echo "<tr><td>»you answered ${$q}, which is correct</td></tr>"; } elseif ($$q == "") { echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>"; } else { echo "<tr><td>»you answered ${$q}. The answer is $answer</td></tr>"; } } echo "</table></p>"; } ?> thanks in adavance Hello I have one problem with fwrite() I have one script to get width and height from javascript and echo it with PHP. echo "Screen width is: ". $_GET['width'] ."<br />\n"; echo "Screen height is: ". $_GET['height'] ."<br />\n"; It works but i want to store the result in a file fwrite($info,"Height: $_GET['height'] <br />"); But then I get error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING //////////////////////// it would be even better if I don't have to print the values but directly store them in $iinfo sorry if something similar was soved but those examples were different or i was unable to transform it to solve my problem I am trying to put a href on a line to link me to another php module, but get an error: Parse error: parse error in C:\wamp\www\editpolicy.php on line 47 My code: while ($row2 = mysql_fetch_array($result2) ) { print "<tr><td>"; <a href='editpayment.php?payid=$row2[PaymentID]'>$row2[PaymentID]</a> .........THIS IS LINE 47 ??? print "</td><td>"; print $row2['Actioned']; print "</td><td align='right'>"; print $row2['PremiumPaidAmount']; print "</td><td align='right'>"; print $row2['Risk']; print "</td></tr>"; } echo "</select></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Views Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_views\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_views').val('');$('#ad_total_views').attr('disabled','disabled');}else{$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');$('#ad_total_views').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Clicks Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_clicks\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_clicks').val('');$('#ad_total_clicks').attr('disabled','disabled');}else{$('#ad_total_clicks').val('');$('#ad_total_clicks').removeAttr('disabled');$('#ad_total_clicks').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n </table></td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\">Smarty Code (Developer)</td>\r\n <td>{\$ads->getAdCode(<span id=\"smartycode\">1</span>)}</td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\"> </td>\r\n <td><input type=\"button\" value=\"Create New Campaign\" onclick=\"new_ad()\" /></td>\r\n </tr>\r\n </TBODY></TABLE>\r\n<br />\r\n\r\n<TABLE cellSpacing=1 cellPadding=4 width=\"100%\" border=0>\r\n <TBODY>\r\n <TR class=\"td_title\">\r\n <TD colSpan=7>Ad Campaigns</TD></TR>\r\n <TR bgColor=#ffffff>\r\n \r\n <TD width=\"10%\" align=\"center\" class=\"td_th\"> </TD>\r\n <TD width=\"4%\" align=\"center\" class=\"td_th\">ID</TD>\r\n <TD width=\"29%\" align=\"center\" class=\"td_th\">Campaign Name</TD>\r\n <TD width=\"12%\" align=\"center\" class=\"td_th\">Start Date</TD>\r\n <TD width=\"11%\" align=\"center\" class=\"td_th\">End Date</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Viewed / Views Allowed</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Clicked / Clicks Allowed</TD>\r\n </TR>\r\n "; $BoxSize = array("smallbox" = array("length" => 12, "width" => 10, "depth" => 2.5), "mediumbox" = array("length" => 30, "width" => 20, "depth" => 4), "largebox" = array("length" => 60, "width" => 40, "depth" => 11.5)); Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick |