Jump to content

can't upload image/files problem

Recommended Posts

Once again, I got a problem with a hosting where I can't upload images/files.

It just uploads to 100% then the bar disappears and it's like before. In the post I see this message:

  1. error: false
  2. message: "Page not saved (no changes)"

Filepermission seems ok. Install went normal. Any ideas what to look for? I can provide phpinfo if needed.

PHP version is:


Share this post

Link to post
Share on other sites

Soma, send me the phpinfo if you can. I'm wondering about any safe mode or open basedir settings.

Share this post

Link to post
Share on other sites

I sent you a PM. Thanks. Safe mode is off.

Share this post

Link to post
Share on other sites

I tried again with debug turned on. This seems to be issue with open_basedir

Warning: tempnam() [<a href=function.tempnam'>function.tempnam</a>]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www:/usr/share/php) in /var/www/web8/web/pw/wire/core/Upload.php on line 126

Can you tell me what I should tell them?

Share this post

Link to post
Share on other sites

Soma, try setting PHP to use a different upload tmp dir, from your /site/config.php

ini_set('upload_tmp_dir', dirname(__FILE__) . '/assets/cache/'); 

Share this post

Link to post
Share on other sites

Thanks for the suggestions. I tried and not luck. It seems it can't be overwritten.

Share this post

Link to post
Share on other sites

The hoster reponded that the function http://php.net/manua...et-temp-dir.php is the problem, in that it returns the default temp dir /tmp always, and she's not confident with adding this because of security reasons.

Edit: and she says that this sys_get_temp_dir isn't compatible with open_basedir... what do you think?


Strange, when I add instead of sys_get_temp_dir -> realpath( $_ENV['TMPDIR']); the upload works, althought it throws an notice which hinders the image to be shown. It show after reloading the page. So it seems to upload.

The notice I get is:

<b>Notice</b>: Undefined index: TMPDIR in <b>/var/www/web8/web/pw/wire/core/Upload.php</b> on line <b>125</b><br />

[{"error":false,"message":"Added file: teflon2.jpg","file":"\/pw\/site\/assets\/files\/1001\/teflon2.jpg","size":129854,"markup":

realpath( $_ENV['TMPDIR']) : returns -> /var/www/web8/web

sys_get_temp_dir: returns -> /tmp


When I add @ before the @realpath( $_ENV['TMPDIR'] ); it works without the notice...

What you do think Ryan? How is this possible, and how to fix it so it works for all scenarios?

Share this post

Link to post
Share on other sites

Soma, the code we're using right now to find the upload temp directory is this:

$dir = ini_get('upload_tmp_dir');
if(!$dir || !is_writable($dir)) $dir = sys_get_temp_dir();

sys_get_temp_dir() is only used as a fallback if the system has no defined upload_tmp_dir.

I would think that if a host were to be using open_basedir() they should at least set an upload_tmp_dir in their PHP, or at the very least, allow you to set it (with a site-specific php.ini or something). It seems like their PHP settings may be set to discourage use of file uploads. Here's a couple of related threads:

The error you are getting with the $_ENV['TMPDIR'] indicates that there's no value set for TMPDIR. So your realpath() call is very likely operating on the value NULL and returning the web root (which may be writable, but not desirable).


Edit: just added a new $config->uploadTmpDir that you can set in your /site/config.php. This will override PHP's upload_tmp_dir for ajax uploads only (I don't think we can override that on non-ajax uploads). I recommend creating this dir:


Then add it to the disallowed directories in your .htaccess file. Basically add it in with the other assets dirs like cache and sessions.

Then update your /site/config.php:

$config->uploadTmpDir = dirname(__FILE__) . '/assets/uploads/';

Now see if it works?

Share this post

Link to post
Share on other sites

Thanks so much Ryan for the active help! But finally we sorted it out, and she agreed to add the /var/.../phptmp folder, that was already there in the web root, to the php ini "upload_tmp_dir". Now it works again flawless.

Anyway, the new available option you implemented may come in useful for someone.

  • Like 1

Share this post

Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Nicole Bardales
      Hi! I'm learning more about ProcessWire and PHP in general by practicing on the different modules.
      I created a test form using the SimpleContactForm module and just adding 1 text field, 1 image upload and 1 file upload field. I've alternated between just one or the other and having both uploads.
      Without the upload fields, the form gets handled correctly and is stored as a page, however when I add an upload field it returns the following error:
      Fatal error: Uncaught Error: Call to a member function path() on null in C:\xampp\htdocs\avanzademo\wire\modules\Fieldtype\FieldtypeFile.module:220 Stack trace: #0 C:\xampp\htdocs\avanzademo\wire\core\WireHooks.php(924): ProcessWire\FieldtypeFile->hookProcessInput(Object(ProcessWire\HookEvent)) #1 C:\xampp\htdocs\avanzademo\wire\core\Wire.php(450): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldImage), 'processInput', Array) #2 C:\xampp\htdocs\avanzademo\wire\core\InputfieldWrapper.php(961): ProcessWire\Wire->__call('processInput', Array) #3 C:\xampp\htdocs\avanzademo\wire\modules\Inputfield\InputfieldForm.module(155): ProcessWire\InputfieldWrapper->___processInput(Object(ProcessWire\WireInputData)) #4 C:\xampp\htdocs\avanzademo\wire\core\Wire.php(383): ProcessWire\InputfieldForm->___processInput(Object(ProcessWire\WireInputData)) #5 C:\xampp\htdocs\avanzademo\wire\core\WireHooks.php(823): ProcessWire\Wire->_callMethod('___processInput', Array) #6 C:\xampp\htdocs\avanzademo\wire\core\Wire.php(450): ProcessWi in C:\xampp\htdocs\avanzademo\wire\modules\Fieldtype\FieldtypeFile.module on line 220 I've been looking into the mentioned files but can't seem to find the exact error. I also looked through a couple of the posts already discussing similar issues in the forum but I can't quite pinpoint what would be a viable solution for this. 
      If anyone can help point me in the right direction, I'd greatly appreciate it.
    • By Sten
      Sorry I can't find any submit button to save my configuration on a template in the admin interface. The file is fine.
    • By nabo
      this is my snippet
      public function init() { if($this->wire('user')->isSuperuser()) { $this->wire()->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildForm'); $this->wire()->addHookBefore('ProcessPageEdit::processInput', $this, 'saveForm'); } } public function buildForm(HookEvent $event) { $p = $event->object->getPage(); $inputfields = $event->return; $fieldset = $this->wire('modules')->get("InputfieldFieldset"); $fieldset->attr('id', 'my_fieldset'); $fieldset->label = __("My Renders"); $fieldset->collapsed = Inputfield::collapsedYes; $field = $this->wire('modules')->get("InputfieldTextarea"); $field->attr('name', 'renders'); $field->attr('value', $p->renders); $field->label = $this->_('Renders'); $fieldset->append($field); $inputfields->append($fieldset); } public function saveForm($event) { $page = $this->pages->get($this->input->post->id); $page->set('renders', $this->input->post->renders); } It builds correctly the inputs, I edit the field renders but when I save the page the value of this inputfield remain blank.
      What's wrong?
    • By carlitoselmago
      I'm building a fieldtype/inputfield to visually select a grid like Bootstrap since it's the first time coding such thing, I'm basing my code in FieldtypeColorPicker since the base structure is the same, a graphical UI helper to finally output a string as value.
      The problem is I try to save the value as something like "1,2,3" referencing the index of each column selected but it gets converted as an int value so "1,2,3" becomes "1" if input random text it gets converted as "0".
      Here is the code:
      Here's an screenshot of how it looks

    • By bramwolf
      Hi Guys,

      I found that my site is producing this notice on the front end, even when $config->debug = false and also when admin is
      not even logged in. How do I keep the site from displaying this message to front end users? The notice is about a few vars
      being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance
      wrap the $discountCode = blabla in a if($order) { ...  } statement than I'm again testing for $order which isn't a object in this case
      which throws another notice..

      This is the notice:

      Here is my current code:
      // PAD DISCOUNT CODE HOOK // First we see if we have active discount code if ($this->session->orderId) { $order = $this->pages->get($this->session->orderId); } if($product->geen_korting == 1) { $nodisc = $product->geen_korting; } else { $nodisc = $product->parent->geen_korting; } $discountCode = $this->sanitizer->selectorValue($order->pad_discount_code); $dc = $this->pages->get("template=paddiscount, title=$discountCode"); if ($dc->id) { if ($nodisc) { $discount = 0; } elseif ($dc->pad_percentage) { $discount = $newprice * ($dc->pad_percentage / 100); } } $event->return = $newprice - $discount;
      Thanks in advance 🙂
  • Create New...