Reply to Re: Upload without reload the page

Re: Upload without reload the page new!
by MDC888, 14 years ago
I found the solution.
The upload class needs an array as parameter.

Here is a draft code if someone else needs it :

include('class.upload.php');

$id  = $_GET['sessionId'];
$id = trim($id);

session_name($id);
session_start();
$inputName = $_GET['userfile'];
$fileName  = $_FILES[$inputName]['name'];
$tempLoc   = $_FILES[$inputName]['tmp_name'];

// Prepare datas for upload class
$arr = array ( 
  'name' => $fileName,
  'type' => 'image/jpeg',
  'tmp_name' => $tempLoc,
  'error' => 0,
  'size' => '' ) ; // Don't know the size at this step
  
$target_path = 'uploads';
  
// ---------- IMAGE UPLOAD ----------

// we create an instance of the class, giving as argument the PHP object
// corresponding to the file field from the form
// All the uploads are accessible from the PHP object $_FILES
$handle = new Upload($arr);

// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {

  // yes, the file is on the server
  // below are some example settings which can be used if the uploaded file is an image.
  $handle->image_resize            = true;
  $handle->image_ratio_y           = true;
  $handle->image_x                 = 300;

  // now, we start the upload 'process'. That is, to copy the uploaded file
  // from its temporary location to the wanted location
  // It could be something like $handle->Process('/home/www/my_uploads/');
  $handle->Process($target_path);

  // we check if everything went OK
  if ($handle->processed) {
      // everything was fine !
      $_SESSION['dhxvlt_state'] = -1;
  } else {
      // one error occured
      $_SESSION['dhxvlt_state'] = -3;
  }

  // we delete the temporary files
  $handle-> Clean();
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important