Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/03/2012, 11:02
SeaPirates
 
Fecha de Ingreso: enero-2009
Ubicación: España
Mensajes: 786
Antigüedad: 15 años, 3 meses
Puntos: 9
El archivo temporal en upload de archivos se borra

Hola, tengo un problema al subir archivos pesados a mi servidor 700mb- 1,5GB.

Como están mucho rato por alguna razón el archivo temporal se borra, o cambia de nombre y cuando finaliza da error de que no se encontró el archivo temporal.

¿Que puede ser y que solución puede haber?

Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4. /**
  5.  * Only needed if you have a logged in user, see option appendCookieData,
  6.  * which adds session id and other available cookies to the sent data.
  7.  *
  8.  * session_id($_POST['SID']); // whatever your session name is, adapt that!
  9.  * session_start();
  10.  */
  11.  
  12. // Request log
  13.  
  14. /**
  15.  * You don't need to log, this is just for the showcase. Better remove
  16.  * those lines for production since the log contains detailed file
  17.  * information.
  18.  */
  19.  
  20. $result = array();
  21.  
  22. $result['time'] = date('r');
  23. $result['addr'] = substr_replace(gethostbyaddr($_SERVER['REMOTE_ADDR']), '******', 0, 6);
  24. $result['agent'] = $_SERVER['HTTP_USER_AGENT'];
  25.  
  26. if (count($_GET)) {
  27.     $result['get'] = $_GET;
  28. }
  29. if (count($_POST)) {
  30.     $result['post'] = $_POST;
  31. }
  32. if (count($_FILES)) {
  33.     $result['files'] = $_FILES;
  34. }
  35.  
  36. // we kill an old file to keep the size small
  37. if (file_exists('script.log') && filesize('script.log') > 102400) {
  38.     unlink('script.log');
  39. }
  40.  
  41. $log = @fopen('script.log', 'a');
  42. if ($log) {
  43.     fputs($log, print_r($result, true) . "\n---\n");
  44.     fclose($log);
  45. }
  46.  
  47.  
  48. // Validation
  49.  
  50. $error = false;
  51.  
  52. if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
  53.     $error = 'Invalid Upload';
  54. }
  55.  
  56. /**
  57.  * You would add more validation, checking image type or user rights.
  58.  *
  59.  
  60. if (!$error && $_FILES['Filedata']['size'] > 2 * 1024 * 1024)
  61. {
  62.     $error = 'Please upload only files smaller than 2Mb!';
  63. }
  64.  
  65. if (!$error && !($size = @getimagesize($_FILES['Filedata']['tmp_name']) ) )
  66. {
  67.     $error = 'Please upload only images, no other files are supported.';
  68. }
  69.  
  70. if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )
  71. {
  72.     $error = 'Please upload only images of type JPEG, GIF or PNG.';
  73. }
  74.  
  75. if (!$error && ($size[0] < 25) || ($size[1] < 25))
  76. {
  77.     $error = 'Please upload an image bigger than 25px.';
  78. }
  79. */
  80.  
  81.  
  82. // Processing
  83. move_uploaded_file($_FILES['Filedata']['tmp_name'], 'uploads/' . $_FILES['Filedata']['name']);
  84. $return['src'] = '/uploads/' . $_FILES['Filedata']['name'];
  85.  
  86.  
  87. if ($error) {
  88.  
  89.     $return = array(
  90.         'status' => '0',
  91.         'error' => $error
  92.     );
  93.  
  94. } else {
  95.  
  96.     $return = array(
  97.         'status' => '1',
  98.         'name' => $_FILES['Filedata']['name']
  99.     );
  100.  
  101.     // Our processing, we get a hash value from the file
  102.     $return['hash'] = md5_file($_FILES['Filedata']['tmp_name']);
  103.  
  104.     // ... and if available, we get image data
  105.     $info = @getimagesize($_FILES['Filedata']['tmp_name']);
  106.  
  107.     if ($info) {
  108.         $return['width'] = $info[0];
  109.         $return['height'] = $info[1];
  110.         $return['mime'] = $info['mime'];
  111.     }
  112.  
  113. }
  114.  
  115.  
  116. // Output
  117.  
  118. /**
  119.  * Again, a demo case. We can switch here, for different showcases
  120.  * between different formats. You can also return plain data, like an URL
  121.  * or whatever you want.
  122.  *
  123.  * The Content-type headers are uncommented, since Flash doesn't care for them
  124.  * anyway. This way also the IFrame-based uploader sees the content.
  125.  */
  126.  
  127. if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') {
  128.     // header('Content-type: text/xml');
  129.  
  130.     // Really dirty, use DOM and CDATA section!
  131.     echo '<response>';
  132.     foreach ($return as $key => $value) {
  133.         echo "<$key><![CDATA[$value]]></$key>";
  134.     }
  135.     echo '</response>';
  136. } else {
  137.     // header('Content-type: application/json');
  138.  
  139.     echo json_encode($return);
  140. }
  141.  
  142. ?>

Última edición por SeaPirates; 22/03/2012 a las 11:08