Jump to content

increase

Members
  • Posts

    15
  • Joined

  • Last visited

increase's Achievements

Member

Member (2/5)

0

Reputation

1

Community Answers

  1. I have a text file in the following format 03/12/2023 06 This is the text in the line 03/12/2023 06 This is the text in the line 03/12/2023 06 This is the text in the line 03/12/2023 06 This is the text in the line 22/11/2023 06 This is the text in the next line 22/11/2023 06 This is the text in the next line 03/11/2023 06 This is another text in the line 03/11/2023 06 This is another text in the line 03/11/2023 06 This is another text in the line 04/12/2023 06 This is yet another text in the line 04/12/2023 06 This is yet another text in the line Which is read into an array $data, from this array, I want to output the earliest date which in this case would be 03/11/2023
  2. I want to backup mp3 files from a server folder to a local folder can this be done in php which is server side. I tried many scripts claiming to do this but all result in 'failed to open stream: No such file or directory' because the code is looking for the destination on the server, not the local directory. Here is an example that says it can be done. ini_set('display_errors',1); error_reporting(E_ALL); $source = "https://domain.com/2024-2021/path_to_file/test.mp3"; echo "src is ", $source; $destination = "C:/backup/2024-2021/Cpath_to_file/"; file_put_contents($destination, file_get_contents($source)); echo "OK"; This one also claims to 'force' the download $file = '/path/to/files/photo.jpg'; if (is_file($file)) { sendHeaders($file, 'image/jpeg', 'My picture.jpg'); $chunkSize = 1024 * 1024; $handle = fopen($file, 'rb'); while (!feof($handle)) { $buffer = fread($handle, $chunkSize); echo $buffer; ob_flush(); flush(); } fclose($handle); exit; } But has the same problem, in that it fails when opening the local folder to write the file, is there a way to do this?
  3. Because I had spent many hours trying all different ways to pass the name data from the form input to php, the commented out option was hard to find for me. Still it is the end result that matters, which is now problem resolved.
  4. I have it! Instead of trying to change the filename back to the original filename after the processing, there was an option buried in the form data javascript, that cariies the filname into the upload.php file FilesAdded: function(up, files) { plupload.each(files, function(file) { document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>'; }); }, FilesAdded: function(up, files) { plupload.each(files, function(file) { document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>'; up.setOption('url', 'upload.php?name=' + file.name); }); }, By adding the line up.setOption('url', 'upload.php?name=' + file.name); to the function it picks up the original filename and processes that instead of the file code name. Works perfectly, thanks for your help
  5. Yes I did take your advice with echoes throughout and error reporting at the top of the script ini_set('display_errors',1); error_reporting(E_ALL); here is the src.txt and dest txt dest.txt src.txt
  6. Forgetting about all the preceding code and keeping it simple 1.set $src = exisitng file. 2. Set $dest = new name. $fileMoved = rename($src, $dest); if($fileMoved){ echo 'Success!'; } the $src file disappears in the directory but the $dest file does not appear, would be really grateful for some suggestion as to the problem with rename I cannot get rename to work with two variable and a change of name in the $dest variable If I use rename($src, "temporary.mp3"); it works
  7. Thank you for doing that, I actually posted the code at the request of another members post. what i am asking is very simple, when I use the rename function, to move a file from one location to another, with a new name, the new file does not appear in the destination directory so rename($src, $dest); does not work even though the $src and $dest are shown to be correct from the two text files I included scr.txt and dest.txt at the end of the rename the file disappears from the source directory but does not appear in the destination directory. But if I do this rename($src, "the_new_name_of_the_file.mp3"); it works perfectly
  8. I thought it was fixed but it isn't, this is a very strange issue Here is my code to get the original name // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$filePath}.part", $filePath); //start of name search $searchthis = 'filename'; $matches = array(); $handle = @fopen($filePath, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle); if(strpos($buffer, $searchthis) !== FALSE) $matches = $buffer; } fclose($handle); } $word = $matches; $words = explode(' ', $word); foreach($words as $ws) { if(strlen($ws) > 0) { $new_word[] = $ws; } } $cnt = count($new_word); $cnt = $cnt-1; $line = $new_word[3]; $new_word[3] = str_replace('filename="', ' ', $new_word[3]); $new_word[3] = str_replace(' ', '', $new_word[3]); $new_word[$cnt] = str_replace('"', '', $new_word[$cnt]); array_shift($new_word); array_shift($new_word); array_shift($new_word); $original_name = implode(" ",$new_word); $new = str_replace('/home2/username/domains/domain_name/public_html/plupload//', '', $filePath); $src = "/home2/username/domains/nerjabible.com/public_html/plupload/$new"; $dest = "/home2/username/domains/nerjabible.com/public_html/path_to_the_file/Genesis _ Mad Man Moon.mp3"; $file1 = "src.txt"; $fp = fopen($file1, 'w'); fwrite($fp, $src); fclose($fp); $file2 = "dest.txt"; $fp = fopen($file2, 'w'); fwrite($fp, $dest); fclose($fp); rename($src, $dest); } the output from src.txt is /home2/username/domains/path_to_the_file/file_627d388928b7d and the output from dest.txt is /home2/username/domains/path_to_the_file/Genesis _ Mad Man Moon.mp3 but after the rename, the destination directory does not contain the file. but if I change $dest to $dest = "/home2/username/domains/path_to_the_file/Genesis _ Mad Man Moon.mp3"; it works perfectly
  9. Thank you I managed to fix it, the problem was in the code
  10. I am using this line of code to rename a file that has beeuploaded to my server rename("{$filePath}.part", $original_name); Where filePath is this file file_6278ea910fbf3 and the rename $original_name is the variable which contains the text ine below Genesis _ Mad Man Moon _ A Trick Of The Tail (2007 Remaster) HQ Audio (128 kbps).mp3 when the rename fuction completes the file file_6278ea910fbf3 disappears off the directory on the server, but if I use this rename("{$filePath}.part", "Genesis _ Mad Man Moon _ A Trick Of The Tail (2007 Remaster) HQ Audio (128 kbps).mp3"); It works perfectly How can I make the variable $original_name reflect the same text, is there a 'normlising' option in php?
  11. Thanks, I only get Array ( ) as the output, sorry i am real new to php, here is your code I inserted <?php $file1 = file('.data.txt', FILE_IGNORE_NEW_LINES); $file2 = file('.data1.txt', FILE_IGNORE_NEW_LINES); echo '<pre>' . print_r(array_diff($file2, $file1), 1) . '</pre>'; ?>
  12. Thanks for your help, do I insert your suggested code into my script? Here is the code I am using <?php if ($file1 = fopen(".data1.txt", "r")) { while(!feof($file1)) { $textperline = fgets($file1); echo $textperline; echo "<br>";} if ($file2 = fopen(".data.txt", "r")) { while(!feof($file2)) {$textperline1 = fgets($file2); echo $textperline1; echo "<br>";} fclose($file1); fclose($file2); }} ?>
  13. I have two text files of data the first file has 30 lines of data and matches with 30 lines in the second text file, but in addition the first text file has two additional lines that are added as the operator uploads file to the directory I want to find the non matching lines and out put them to be used in the same script as a mailout. I am trying to use if (strcmp($textperline, $textperline1) !== 0) { echo 'Both strings are not equal'; echo $textperline1; // the line that is different echo "<br>"; } But it outputs the whole list of data, can anyone help listingout only NON matching lines?
×
×
  • 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.