Jump to content
Tom.

WireUpload not working correctly?

Recommended Posts

I have a script that I would like to upload and make sure the files keep it's file name. This is a multi-image image field. 

Just using $p->images->add($_FILES['file']['tmp_name']) works. However this doesn't: 

if(count($_FILES['file']) != 0) {
  $p->images->removeAll();

  $u = new WireUpload('file');
  $u->setDestinationPath($p->images->path);
  foreach($u->execute() as $filename) $p->images->add($filename);
}

if(!$error) $p->save();

There is no error given, however non of the images are added? What am I missing here?

 

Edit:

print_r($u);
print_r($u->execute());

Both return an empty array. I'm guessing WireUpload('file') doesn't use $_FILES and there for can not be used with DropZone? 

Edit2: 
WireUpload does use $_FILES. There is some sort of bug happening here with using Ajax and WireUpload.

Share this post


Link to post
Share on other sites
1 hour ago, Tom. said:

Edit:


print_r($u);
print_r($u->execute());
1 hour ago, Tom. said:

What am I missing here?

You are obviously missing TracyDebugger 😉😄 SCNR, but joke aside, tracy does also help you a lot on ajax debugging. It has fl() = firelog and bd() = bardump that can help a lot to see what's going on!

A quick guess: If you are using custom AJAX scripts it might be the case that the headers are not set correctly so that PW recognizes it as $config->ajax == true. Maybe that's not at all helpful, not sure, but in a hurry 🙂

 

  • Like 2

Share this post


Link to post
Share on other sites
38 minutes ago, bernhard said:

You are obviously missing TracyDebugger 😉😄 SCNR, but joke aside, tracy does also help you a lot on ajax debugging. It has fl() = firelog and bd() = bardump that can help a lot to see what's going on!

A quick guess: If you are using custom AJAX scripts it might be the case that the headers are not set correctly so that PW recognizes it as $config->ajax == true. Maybe that's not at all helpful, not sure, but in a hurry 🙂

 

I believe it's an issue with DropZone. I've decided to do the following:

		if(count($_FILES['file']) == 0) {
			$error = "Please upload your entries.";
		} else {
			$count = count($_FILES['file']['name']);

			for($i = 0; $i < $count; $i++) {
				$file = $p->images->path . $sanitizer->pageName($_FILES['file']['name'][$i]);

				if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $file)) {
					$p->images->add($file);
				}
			}
		}

		if(!$error) $p->save();

Which works a charm 🙂 Thanks @bernhard

  • Like 1

Share this post


Link to post
Share on other sites

It would be really good if image->add had a second argument for image name 🤔

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...