Jump to content

[SOLVED] Bootstrapping PW gets Class 'WireUpload' not found


Xonox
 Share

Recommended Posts

Hi,

I'm trying to figure what's happening here.

Objective

The site administrator uploads, via FTP, a group of book images. Then, by running a tool in the admin area all the images will be assigned to each book through the SKU in the file name. This is a standalone tool with PW bootstrapped. Working code:

// Get SKU
$file_sku = substr($file, 0, 9);

// Check for book
$book = $pages->get('sku=' . $file_sku);
if(!$book->id) {

	// Book doesn't exist

}
else {

	// Upload image into book
	$book->book_images->add($upload_directory . '/' . $file);

	// Delete file
	unlink($upload_directory . '/' . $file);

}

// Save book
if($book->id) $book->save();

Problem

This code adds to existing files. So when the administrator wants to replace files, instead of replacing it just keeps adding them to existing books.

Alternative

Using WireUpload. I've never used it before, but I think this might be right:

// Get SKU
$file_sku = substr($file, 0, 9);
echo 'SKU: ' . $file_sku . '<br />';

// Check for book
$book = $pages->get('sku=' . $file_sku);
if(!$book->id) {

	// Book doesn't exist

}
else {

	// Upload image into book
	$u = new WireUpload('book_images');
	$u->setMaxFiles(1);
	$u->setOverwrite(false);
	$u->setDestinationPath($book->files->path());
	$u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png'));
	foreach($u->execute() as $filename) $book->files->add($filename);

	// Delete file
	unlink($upload_directory . '/' . $file);

}

// Save book
if($book->id) $book->save();


Error!

With this code I get the following error:

Fatal error: Uncaught Error: Class 'WireUpload' not found in E:\WebServer\sadacosta.com\site\modules\Tools\process-book-images.php:35 Stack trace: #0 E:\WebServer\sadacosta.com\tools-process-book-images.php(4): include() #1 {main} thrown in E:\WebServer\sadacosta.com\site\modules\Tools\process-book-images.php on line 35

What's missing?
Is there any other way to do this?

Thanks,

Link to comment
Share on other sites

  • Xonox changed the title to [SOLVED] Bootstrapping PW gets Class 'WireUpload' not found

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...