Jump to content

can't upload image/files problem


Soma
 Share

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:

PHP/5.2.4-2ubuntu5.23

Link to comment
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?

Link to comment
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?

Edit:

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

Edit:

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?

Link to comment
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:

/site/assets/uploads/

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?

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ErikMH
      So, if I do this right at the top of a template PHP file:
      <?php namespace ProcessWire; function myFunction() { global $config; echo $config->dateFormat; }; ?> I, predictably, get this in my front end (once I figured out about the necessary global $config; line):
      Y-m-d H:i:s Happy camper. But if I try to access $session variables in the same way:
      <?php namespace ProcessWire; function myFunction() { global $session; echo $session->future; }; ?> I’m told there is no $session object; it responds exactly as if I hadn’t included the global $session statement:
      PHP Notice: Trying to get property 'future' of non-object in .../public/site/templates/home.php:5 I thought the problem might conceivably have to do with my private variables, so I tried the provided hasCookie() method:
      <?php namespace ProcessWire; function myFunction() { global $session; print_r($session->hasCookie()); }; ?> With essentially the same result:
      Error Call to a member function hasCookie() on null $session variables and methods are fully accessible and work exactly as expected if placed immediately outside of myFunction().
      I am rapidly running out of hair. Is this intentional? Or a bug? Can anyone confirm that they see this behavior? Can anyone think of a workaround? Thanks!
      ProcessWire: 3.0.179
      PHP: 7.4.19
       
    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By RyanJ
      I have quite the pickle. 
      The admin no matter where I am at in it, times out constantly. I either get a 504 gateway or and execution timeout. I am banging my head why its across the board. The frontend of the site works great.
      The site does have a lot of pages, 164,889 to be exact.  Most of that is due to image pages created by media manager and having repeater matrix installed which is used on most of the pages. For some reason, if I can manage  click the "Clear file compiler" without it timing out, the site perks back up and I can access the admin again and it is quite speedy. However if I walk away leaving the browser sitting for about an hour and come back, I have to start the process all over again.
      The site has 52 various fields. Not every field is assigned to every template. a lot of the fields are used by the matrix to create a page builder.
      I can't accept that PW can't handle such. I have other sites that run triple the amount of pages, but don't rely on the matrix to build the layout.
      I have disabled any custom module that I thought could possibly cause an issue. I have overwrote every module and the wire core thinking something may have got corrupted. I guess my next step is starting with a fresh install, but I thought I would reach out to see if I am missing something. 
      Some background on pages:
      All the pages are imported using the command line which bootstraps PW and uses the api. This is a dev site, so I blow away the pages if I need to reimport them, until I get it correct.
      PW Version 3.0.172, PHP 7.3, Innodb 5.7.27-30.
      I appreciate any suggestions or thoughts. 

       

       

    • By Marvin
      Hi,
      I'm still new at processwire, i want to ask, i was create a website with sign in system, but i want to add a access roles/permission for each user at my website. For now, i just can create a login user without any permission and the user data became as a pages in my processwire.
      Here i attach my code for login
      <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } if($input->post->submit) { $email = $sanitizer->email($input->post->email); $pass = $sanitizer->text($input->post->pass); $result = $pages->find("email=$email, text_1=$pass"); if(!$email || !$pass) { $note = "Data belum lengkap"; } else { if($result->count > 0) { $session->login_id = "$result"; $hidden = "style = 'diplay:none'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } else { $note = "Akun tidak ditemukan"; } } } ?> And this code for login form
      <div class="frow-container"> <div class="frow centered mt-50"> <div class="col-md-1-3"> <div class="box p-40 shadow-light"> <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2> <form method="post" <?=$hidden?>> <label>Username <input type="text" name="email"></label> <label>Password <input type="password" name="pass"></label> <input type="submit" name="submit" value="Masuk"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div> Just for remember, my user data now is a pages, and i cannot give any permission to user data.
      Thank you very much for help.
    • By Marvin
      Hello,
      I'm new at process wire and i want to make an web using upload file and showing it at the table as a link to open it at the new tab. I wa succed while upload a file, but how i showing it as a link at the table to open it at the new tab of my browser? Any suggestion may helpfull
      Here i attach my code below :
      This code is for upload it to back-end (process wire)
      <?php $note = $note2 = $hidden =""; if($input->post->submit){ $upload_path = $config->paths->assets.'files/upload/'; if(!is_dir($upload_path)){ if(!wireMkdir($upload_path)) throw new WireException("No upload path"); } $original = $sanitizer->text($input->post->original); $indonesia = $sanitizer->text($input->post->indonesia); $other = $sanitizer->text($input->post->other); $composer = $sanitizer->text($input->post->composer); if(!$original || !$indonesia || !$other || !$composer){ $note = "Data tidak lengkap"; } else { $newFile = new WireUpload("song_files"); $newFile->setMaxFiles(1); $newFile->setOverwrite(false); $newFile->setDestinationPath($upload_path); $newFile->setValidExtensions(array('pdf','docx','doc')); $files = $newFile->execute(); if(!count($files)) { $newFile->error("No files received, so not creating page."); return false; } $newImg = new WireUpload("img_files"); $newImg->setMaxFiles(1); $newImg->setOverwrite(false); $newImg->setDestinationPath($upload_path); $newImg->setValidExtensions(array('jpeg','jpg','png','gif')); $files = $newImg->execute(); if(!count($files)) { $newImg->error("No files received, so not creating page."); return false; } $newPage = new Page(); $newPage->template = "files"; $newPage->parent = $pages->get("/files/"); $newPage->title = $original; $newPage->text_1 = $indonesia; $newPage->text_2 = $other; $newPage->text_3 = $composer; $newPage->of(false); $newPage->save(); foreach($files as $filename) { $filepath = $upload_path . $filename; $newPage->files->add($filepath); $newPage->message("Add file : $filename"); unlink($filepath); } $newPage->save(); } } ?> and this code to showing it as a link at the table
      <table class="border"> <tr> <th>No.</th> <th>Original Song Title</th> <th>Indonesia Song Title</th> <th>Other Song Title</th> <th>Composer</th> <th>File (pdf)</th> </tr> <?php $num = 1; $song; foreach($pages->get("/files/")->children as $child) { //showing every child at files parent directory $page == $child; $song = $pages->get("/files/".$child->id."/")->files; //showing uploaded files at child directory echo $child->id; echo "<tr><td>".$num++.".</td><td>".$child->title."</td><td>".$child->text_1."</td><td>".$child->text_2."</td><td>".$child->text_3."</td><td><a href='".$song->httpUrl."'</a>".$song->name."</td></tr>"; } ?> </table> Thank you for any suggestion
×
×
  • Create New...