Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. You'd have to write code specifically to interpret it and display it that way, it's not something that the browser would do by itself. Depends on what your doing with the result. If you're sending it to a browser, then it depends on whether or not you sent the correct Content-type header. If you did, the browser would render the image. If you didn't, the browser might guess and render the image, might display it as text, or might just offer it as a download.
  2. Yes, fundamentally it all begins as a binary stream of data. Your "What do I see?" question doesn't really make sense because what you see depends on how you decide to interpret that binary data. You can see whatever you want. If you take an JPEG image for example and open it in notepad you'll see that binary data interpreted as text and you'll just see random characters. Which characters specifically would depend on which character set you use. If you open it in a hex editor, you'll see individual bytes represented in hexadecimal format, maybe with ASCII characters along the side for those bytes that match a printable ASCII character. If you open it in a browser, you'd likely see the image rendered as the browser would interpret that string of bytes as image data. If you wanted you could opt to render it as a string of 1s and 0s. Any file just contains "arbitrary binary data". How that data gets interpreted is what gives you your different files, encodings, etc and there's nothing preventing you from interpreting the same data in multiple different ways, it just may not make any sense if you do.
  3. Use usort rather than sort, then you can provide a comparison function and implement whatever logic you need to get the correct sorting. The comparison function will be given two items from the array ($a and $b) and must return a number that indicates if $a is less than $b (-1), they are equal (0), or $a is greater than $b (1). If your files all began with the date in Y-m-d format you'd be able to simply compare them. In m-d-Y format though you need to parse the date out of the name and then compare the date. usort($files, function($a, $b){ $a = basename($a); $b = basename($b); $aDate = DateTime::createFromFormat('!m-d-Y+', $a); $bDate = DateTime::createFromFormat('!m-d-Y+', $b); if ($aDate && $bDate){ $comparison = $aDate <=> $bDate; if ($comparison === 0){ return $a <=> $b; } else { return $comparison; } } else { return $a <=> $b; } }); Here, the function reduces each path given to it's basename, then attempts to parse a date in m-d-Y format from the beginning of the filename. If it's able to successfully parse a date from both filenames then it compares the dates to get that -1, 0, or 1 value indicating their order. If the result is 0, meaning the dates are equal, it compares the entire string and returns that order. If it's unable to parse a date from either of the filenames then it just returns an order based on a string comparison.
  4. instead of that, make your data function return your games variable. return $games; Then you can assign it when you call your data function and access whatever you want. $game = new CsvToArray(); $games = $game->data(); echo $games[64]['Home Team']; Make it a function argument. function data($file){ $fileName = fopen($file,'r+'); ...
  5. Select all the posts for your thread in one sql statement. As you loop over the query results, build a tree structure using an array that has all the posts nested under their parent post. An easy way to do this is by using references. $tree=[]; $map=[]; foreach ($queryResults as &$row){ if ($row['ParentId']){ $map[$row['ParentId']]['children'][] = &$row; } else { $row['children']=[]; $tree[] = &$row; } $map[$row['id']] = &row; } After that the first level of $tree contains all your top level posts. The child posts of each of them are stored in a key called 'children'. To output them all you can use a recursive function. function outputPostTree(array $tree){ echo '<ul>'; foreach ($tree as $post){ echo '<li>'.$post['CommentText']; if ($post['children']){ outputPostTree($post['children']); } echo '</li>'; } echo '</ul>'; }
  6. You have another syntax error there. Extra ).
  7. You have a syntax error here: You're missing your closing ) at the end of your call to prepare().
  8. That's what's happening to your first row. Every time you call fetch_assoc it returns the next row. You call it here to return the first row, but don't ever echo that row data out in the table anywhere. Remove that call and let your loop down below fetch the first row. Since it looks like you're calling it there so you can get the seller name, you'll have to come up with an alternative way to obtain that information or re-arrange your code so you can get the name and all the row data.
  9. PHP will create an array of the posted values if your name ends with []. <input type="hidden" name="draggables[]" id="draggable3"> <input type="hidden" name="draggables[]" id="draggable4"> <input type="hidden" name="draggables[]" id="draggable5"> In your PHP code you can then take that array of values and do whatever you need to with it. The reason your "change" didn't work in the original code is because you only changed the value of the variable x, not the value of the actual input element. Assigning the value to x doesn't link the two, it makes a copy. Changing the copy doesn't change the original. To change the value of the input, you need to assign a new value to the element's .value property. document.getElementById("drag12").value = "draggable3"
  10. Additionally, if the only thing your javascript is going to do is either redirect or show an error, then there's really no reason to use javascript / ajax at all. Just use a normal form process and keep it simple.
  11. It sounds like you might just need to re-consider your design. If it's the client that's interested in whatever this change is, the typical solution to this is to just have the client make a request periodically. One name for this is Ajax Polling. You make an Ajax request to your change detection script. The script will check for the change in a loop and return when a change is detected. You could wait 30 minutes, but it's more typical to wait 30-sec to a minute then return a "No changes" response. This way your web-server's available threads don't get used up waiting. If the change detection is only relevant to the server and not the client, then either cron or a service would be the more appropriate implementation. This sounds like something that's more typically done with a cron job. Your database row would contain a timestamp of when it was created or when it needs to be destroyed. You then schedule a script via cron (or some other scheduler) that runs every minute and deletes any rows that have expired. Similar to above, you don't really want to make a request to your server that just waits for 10 minutes as it'll tie up resources and it's particularly reliable anyway (might timeout / get killed). In regard to your original post, multi-tasking is generally handled by using multiple requests rather than one request that executes sub-scripts. It's possible to execute sub-scripts concurrently like you want, but it's somewhat complicated to do. Sending separate requests is much easier. Browsers do have a limit to how many concurrent requests they will make that you need to keep in mind though.
  12. You need to call session_start() before you use any $_SESSION variable. That function looks up the stored session data and populates $_SESSION.
  13. I downloaded your code and added that attribute and it seemed to be working fine after that. You need to add it to both the CSP and the iframe's sandbox attribute.
  14. What if 5 different users want to make the folder "puppy"? Do you just mix all their files in that folder? What if their files are also all named "cutest.jpg"? Whoever uploads last gets the spot? That's one of the main reasons I just always generate a random name for the actual storage system of uploaded content. You don't have to deal with conflicting names. I generally just do something simple like: $ext = pathinfo($originalName, PATHINFO_EXTENSION); $newName = bin2hex(random_bytes(8)) . '.' . $ext; If I want to serve the files directly. If I serve them via a script instead then I don't worry about the extension and just generate the random name. The original name and MIME type get stored in the db. If you want keep the original names / let users make directories then at minimum isolate each user into a folder you've defined that they cannot manipulate. For example, create a folder based on their auto-generated user ID from the database. Make sure you validate against path traversal attacks so they can't break out of that isolation.
  15. This may be your issue MDN: <iframe>: The Inline Frame element Try adding allow-same-origin to your sandbox attribute.
  16. I'd suggest you try re-encoding the file, maybe in another format, and see if it helps. Light web searching suggests your issue is just that there is no duration metadata available and also suggests that may be somewhat common for .ogg in particular.
  17. If you're initially seeing Infinity then it sounds like whatever media you're trying to play just doesn't have any duration information encoded into it. MDN says (emphsis added): As such, I imagine it's updating the duration as it loads the file which is why you see the increasing time. If this is a file that should have a fixed duration, then maybe it just needs to be re-encoded with that information? I'm not really familiar with OGG or media file formats in general. You could try the loadedmetadata event, but it sounds like it may not help.
  18. You don't await anything, you use the durationchange event. audio.addEventListener('durationchange', function(){ console.log('Duration changed'); setDuration(audio.duration); });
  19. Make the function a named function, function saveRows(){ //... } Then just reference it in both places. Pass a reference to it for your event handler $(document.body).on('click', '#save_rows', saveRows); And call it in your other location. saveRows();
  20. Do you mean uploading via PHP? Have to properly verified that the upload was successful? Maybe the upload is failing for that one file (too large?) and so you end up with $file referencing something that doesn't exist.
  21. You need to send the name of the button also. Use the browsers dev tools or something like Fiddler to inspect all the requests being made and re-create the ones you need as closely as possible.
  22. Databases don't have a concept of order when inserting data. The data is stored in whatever location it will fit. You can only define an order when you're reading data back out of the database using a SELECT query and you do that by using an ORDER BY clause in your query. So if you want your data to display in a specific order, you MUST change your query to include an ORDER BY clause that specifies the ordering you want.
  23. It doesn't matter where in the table the data is stored. When you query your data you want to specify an ORDER BY clause to define what order it will be returned in. If you want the records to display in the order the were added, make sure you have a field that records what date and time the record was added and sort by that field.
  24. Unknown. I just tried again and this time it connected successfully. So either your Arduino was simply off when I tried before, or the request is only sometimes blocked. The fact that it is working now but wasn't before means it's possible you have a problem in your Arduino code. Are you using a library to handle the TCP/IP stuff and HTTP stuff or is it custom? You'll need to spend some time analyzing your setup trying to determine why there are connection problems. If it's possible to SSH into your external bluehost server that would be helpful as you could SSH in and try connecting with curl and get better feedback. I would guess your PHP configuration is fine, but you can use phpinfo() to check the settings.
  25. Like Barand, it times out for me also. The remote host does not respond to the the connection attempt. Wireshark shows all the outgoing SYN packets but no replies. Sounds like you have a networking issue. Either your port forwarding/firewall configuration is not setup properly or your ISP may be blocking the port. If you're fairly sure your forward/firewall is correct try different port numbers.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.