Jump to content
huseyin

Edit & Add image via Page Api

Recommended Posts

Hello, 

i want to build a page for product add and edit. 

Products have also images. 

Is there any way i can include the image user interface like on the backend image field. Drag drop images and editing images. 

 

Is there any complete manual for such a page. 

Or any module for editing with page api (not frontend editing) 

Share this post


Link to post
Share on other sites

You can take a look at this module: 

Or you can build your own image uploader with something like Dropzone.js and some guide from this topic:

I think the main backend code to upload and save image to disk and add to page field is within this post: 

https://processwire.com/talk/topic/67-front-end-image-uploader-like-admin/?do=findComment&comment=3790

$size=filesize($_FILES['imageUpload']['tmp_name']);
	if ($size > MAX_SIZE*1024){
		print 'File troppo grosso';
		exit;
	}
	//copy the image in secure folder
	$image_name=time().'.'.$extension;
	$newname="../site/tmpfiles/profiles/".$image_name;
	$copied = copy($_FILES['imageUpload']['tmp_name'], $newname);
	if ($copied) {
		$userid	= $sanitizer->text($input->post->userid);
		$u = $users->get($userid);
		$u->setOutputFormatting(false);
		$u->profilephoto->add("http://".$_SERVER['HTTP_HOST']."/site/tmpfiles/profiles/".$image_name);
		$u->save();
                       //delete copied image
		$tmpfile = $_SERVER["DOCUMENT_ROOT"]."/site/tmpfiles/profiles/".$image_name;
		if (file_exists($tmpfile)) { unlink ($tmpfile); }

	}else{
		print "Errore nel salvataggio del file.";
		exit;
	}

 

  • Like 1

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...