not submitting as array from form...

See all posts Reply

not submitting as array from form... new!
by dea, 17 years ago
Hey there, we've spoken a ways back. I have a commercial license and am currently trying to integrate your class with Multipowupload, a Flash-based front-end replacement to the standard HTML form that will show status of uploads (http://www.element-it.com/MultiPowUpload.aspx). From what I can gather, this component does not submit an array (like myfield[], instead it automatically names inputs with an incrementing number. My question is, how can I still use your class while not doing the foreach at the start to get things properly set up for processing?
Thanks for any help!Reply
Re: not submitting as array from form... new!
by colin, 17 years ago
I don't know Multipowupload, I will have a look.

But apparently, there is a PHP wrapper for it here. In the cade there for PHP, it seems that it actually populates $_FILES.

In any case, with the class, you can process local files:
$foo->process('/path/to/local/file.jpg');
Wouldn't it be a solution?Reply
Re: not submitting as array from form... new!
by dea, 16 years, 12 months ago
Thanks for the response!

Hmm, interesting on the local files approach, hadn't really looked at that. I guess I still wonder then at how to go through the files I've just uploaded with this module. This is the out of the box snippet that works:

if(count($_FILES) > 0) {
  $arrfile = pos($_FILES);
  $uploadfile = $uploaddir . basename($arrfile['name']);
  if (move_uploaded_file($arrfile['tmp_name'], $uploadfile))
  echo "File is valid, and was successfully uploaded.\n";
} else
  echo 'No files sent. Script is OK!'; //Say to Flash that script exists and can receive files
echo 'Here is some more debugging info:';
print_r($_FILES);

So it's populating $_FILES as you say, but not with a named array (sorry, that's horribly wrong wording) like with your example: $_FILES['myfield']Reply
My upload page code with local processing (not working yet) new!
by dea, 16 years, 12 months ago
include('/uploadclass/class.upload.php');
function makeMyDir($inDirName) {
  $dirArray = split('/', $inDirName);
  $dirName = '/';
  foreach ($dirArray as $dirLevel) {
    $dirName .= $dirLevel.'/';
    if (!file_exists($dirName)) {
      mkdir($dirName, 0755);
    }
  }
}

echo 'Upload result:'; // At least one symbol should be sent to response!!!

$uploaddir = $_SERVER['DOCUMENT_ROOT']."/uploads/";  // path to images
makeMyDir($uploaddir );

if(count($_FILES) > 0) {
  $arrfile = pos($_FILES);
  $uploadfile = $uploaddir . basename($arrfile['name']);

  if (move_uploaded_file($arrfile['tmp_name'], $uploadfile)) 
  
  //FILE IS IN RIGHT DIRECTORY, START THE FUNKY IMAGE HANDLING NOW
  $handle = new Upload($uploadfile);
  $handle->file_new_name_body = strtotime("now");
  $handle->image_resize   = true;
  $handle->image_ratio_y  = true;
  $handle->image_x  = 1024;
  $handle->image_convert = 'jpg';
  $handle->file_auto_rename = false;
  $handle->file_overwrite = true;
  $handle->process($uploadfile);
     
  echo "File is valid, and was successfully uploaded.\n";
} else 
  echo 'No files sent. Script is OK!'; //Say to Flash that script exists and can receive files

echo 'Here is some more debugging info:';
print_r($_FILES);
Reply
Re: My upload page code with local processing (not working yet) new!
by colin, 16 years, 12 months ago
Sorry, i don't have much time to test this now.

You say it doesn't work yet. But does it work in some parts? What do you have working?

When you process the file, what $handle->log says?Reply
Re: not submitting as array from form... new!
by dea, 16 years, 11 months ago
The upload is working in the following code, but none of the resizing is. It appears the upload object is not even getting called somehow.

include('/code/upload/class.upload.php');
function makeMyDir($inDirName) {
  $dirArray = split('/', $inDirName);
  $dirName = '/';
  foreach ($dirArray as $dirLevel) {
	$dirName .= $dirLevel.'/';
	if (!file_exists($dirName)) {
	  mkdir($dirName, 0755);
	  echo "making dir... $dirName ...";
	}
  }
}

echo 'Upload result:'; // At least one symbol should be sent to response!

if (count($_FILES) > 0) {
  $uploaddir = $_SERVER['DOCUMENT_ROOT']."/uploads/";  // path to images
  makeMyDir($uploaddir );

  $arrfile = pos($_FILES);
  $uploadfile = $uploaddir . basename($arrfile['name']);

  if (move_uploaded_file($arrfile['tmp_name'], $uploadfile))
	   
	$handle = new upload($uploadfile);
	$handle->image_resize   = true;
    $handle->file_new_name_body   = 'image_resized';
    $handle->image_ratio_y  = true;
    $handle->image_x        = 1024;
	   
    $handle->process($uploadfile);
	   
    echo "File is valid, and was successfully uploaded.\n";
 } else
	echo 'No files sent!'; //Tell Flash we tanked

echo 'Here is some more debugging info:';
print_r($_FILES);
Reply
Re: not submitting as array from form... new!
by colin, 16 years, 11 months ago
Here's the error:
Replace:
$handle->process($uploadfile);
With:
$handle->process($uploaddir);

You can do some logging like this:
$handle->process($uploaddir);
$f = fopen('log', 'a');
fwrite($f, $handle->log);
fclose($f);
And then open the file called log to see what the class does.Reply
Re: not submitting as array from form... new!
by dea, 16 years, 11 months ago
OMG. I'm the proud recipient of the Biggest Bonehead on the Planet Award this week.

include('/uploadclass/class.upload.php');

That was the issue all along, at least 50%. Updated to
include($_SERVER['DOCUMENT_ROOT']."/code/upload/class.upload.php");
and it works like a charm -- as advertised.

Not sure I can effectively describe my shame at this moment...Reply
Re: not submitting as array from form... new!
by colin, 16 years, 11 months ago
No worries, that kind of thing happens all the time... ;)

Glad it works now.Reply