Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][Php] UPLOAD , DOWNLOAD PLIKÓW
Forum PHP.pl > Forum > Przedszkole
---mako---
MySQL wywala mi bł±d
Fatal error: Can't use function return value in write context in C:\AppServ\www\inc\download_file.php on line 7

Chodzi o ten wiersz
list ($fn, $ft, $fsmysql_fatch_array ($result, MYSQL_NUM);


Cało¶ć wygl±da tak
Download file
  1. <?php include('header.inc'); ?>
  2. <?php
  3. require_once ('config.php');
  4. if (is_numeric ($GET['uid'])) {
  5. $query = "SELECT file_name, file_type, file_size FROM uploads WHERE upload_id = {$_GE
    T['uid']}"
    ;
  6. $result = mysql_query ($query);
  7. list ($fn, $ft, $fsmysql_fatch_array ($result, MYSQL_NUM);
  8. $EXTETENSION = explode ('.', $fn);
  9. $the_file = './test/' . $_GET['uid'] .'.' . $extension[1];
  10. if (file_exists ($the_file))[
  11. header ("Content-Type: application/$ft");
  12. header ("Content-disposition: atachment; filename=$fn");
  13. header ("Content-Lenght: $fs");
  14. readfile ($the_file); 
  15. }
  16. $message = ' Wysłano';
  17. } else { 
  18. $message = ' Prosze wybprac plik';
  19. $page_title = 'Pobieranie pliku';
  20. echo $message
  21. ?>
  22. <?php include('stopka.inc'); ?>

Upload file
  1. <?php
  2. $page_title = 'Upload a File';
  3.  
  4.  
  5. if (isset($_POST['submit'])) { 
  6.  
  7. require_once ('config.php'); 
  8.  
  9. // Function for escaping and trimming form data.
  10. function escape_data ($data) {
  11. global $dbc;
  12. if (ini_get('magic_quotes_gpc')) {
  13. $data = stripslashes($data);
  14. }
  15. return mysql_real_escape_string (trim ($data), $dbc);
  16. } // End of escape_data() function.
  17.  
  18. // Check for a description (not required).
  19. if (!empty($_POST['description'])) {
  20. $d = escape_data($_POST['description']);
  21. } else {
  22. $d = '';
  23. }
  24.  
  25.  
  26. $query = "INSERT INTO uploads (file_name, file_size, file_type, description, upload_date) VALUES ('{$_FILES['upload']['name']}', {$_FILES['upload']['size']}, '{$_FILES['upload']['type']}', '$d', NOW())";
  27. $result = @mysql_query ($query);
  28.  
  29. if ($result) {
  30.  
  31. // Create the file name.
  32. $extension = explode ('.', $_FILES['upload']['name']);
  33. $uid = mysql_insert_id(); // Upload ID
  34. $filename = $_FILES['upload']['name'];
  35.  
  36. // Move the file over.
  37. if (move_uploaded_file($_FILES['upload']['tmp_name'], "./test/$filename")) {
  38. echo '<p><font color="white"><center>Plik został zapisany</center></font></p>';
  39. } else {
  40. echo '<p><font color="white"><center>Plik nie może być przeniesiony</center></font></p>';
  41.  
  42.  
  43. $query = "DELETE FROM uploads WHERE upload_id = $uid";
  44. $result = @mysql_query ($query);
  45. }
  46.  
  47. } else { 
  48. echo '<p><font color="white"><center>Błąd połączenie z bazą danych MySQL</center></font></p>';
  49. }
  50.  
  51.  
  52. } 
  53. ?>

view_file
  1. <?php
  2.  
  3. $first = TRUE; //Initialize the variable.
  4.  
  5. //query the db
  6. $query = "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description,
  7. DATE_FORMAT(upload_date, '%M %e, %Y') AS d FROM uploads ORDER BY upload_date DESC";
  8. $result = mysql_query ($query);
  9.  
  10. //Display all the URLs
  11. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  12.  
  13. //If this is the first record then create the table header
  14. if ($first) {
  15. echo '<table border="1" width="383" cellspacing="3" cellpadding="3" align="center">
  16. <tr>
  17. <td align="left" width="20%"><font size="1px" color="#EDE3EB"><b>Nazwa Pliku</b></font></td>
  18.  
  19. <td align="center" width="20%"><font size="1px" color="#EDE3EB" >Wielkosć</font></td>
  20. <td align="left" width="20%"><font size="1px" color="#EDE3EB" >Data</font></td>
  21. <td align="left" width="40%"><font size="1px" color="#EDE3EB" >Opis</font></td>
  22. </tr>';
  23. } //End of first IF
  24.  
  25. //Display each record
  26. echo " <tr>
  27. <td align=\"left\" class=\"ramka2\"><font color=\"white\"><a href=\"download_file.php?uid={$row['upload_id']}\">{$row['file_name']}</a></font></td>
  28.  
  29. <td align=\"center\"class=\"ramka2\" ><font color=\"black\">{$row['fs']}kb</font></td>
  30. <td align=\"left\"class=\"ramka2\" ><font color=\"black\">{$row['d']}</font></td>
  31. <td align=\"left\"class=\"ramka2\" ><font color=\"black\">" . stripslashes($row['description']) . "</td>
  32. </tr>\n";
  33.  
  34. $first = FALSE; //one record has been returned
  35. } //End of while loop
  36.  
  37. //If no records were displayed...
  38. if($first) {
  39. echo '<div align="center"> There are currently no files to be viewed.</div>';
  40. } else {
  41. echo '</table>'; //Close table
  42. }
  43.  
  44. $result = mysql_query ($query) or die("Query failed: $query - ".mysql_error());
  45. mysql_close(); //Close the db connection
  46.  
  47. ?>
drPayton
To co napisałeś generuje błąd składni. Jeżeli tak naprawdę jest w oryginale to najpierw popraw to i dopiero poprawione pokaż:
  1. <?php
  2. list ($fn, $ft, $fsmysql_fatch_array ($result, MYSQL_NUM);
  3. ?>

Brak nawiasu zamykającego, po $fs nie powinno być przecinka? I fetch a nie fatch.
Tak to ciężko się domyśleć o co Ci chodzi...

No i zobacz TU jak działa list() i jakie są warunki do jej stosowania

Pozdrawiam!
To jest wersja lo-fi głównej zawarto¶ci. Aby zobaczyć pełn± wersję z większ± zawarto¶ci±, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.