form is uploading to /tmp/phpHQ6U5X instead of newly set /var/www/html/upload_tmp

136
April 15, 2019, at 06:00 AM

I am trying to upload files to my server through a CRUD. I am having an issue moving the uploaded file to its new directory which exists.

I am receiving this warning..

Warning: move_uploaded_file(../images/me.png): failed to open stream: Permission denied in /var/www/html/admin/addpicture.php
Warning: move_uploaded_file(): Unable to move '/tmp/phpHQ6U5X' to '../images/me.png'

Realizing this might be a permission issue with /tmp, I decided to change the temporary upload folder.

I set a temporary upload folder in the php.ini file I found listed in phpinfo()

Configuration File (php.ini) Path   /etc/php/7.0/apache2

I restarted my server using

sudo systemctl restart apache2

I checked to make sure my changes were set with phpinfo() again

upload_tmp_dir  /var/www/html/upload_tmp

Also, I checked to see if my basedir is set

open_basedir    no value

I tried to upload the file again

Warning: move_uploaded_file(): Unable to move '/tmp/phpHQ6U5X' to '../images/me.png'

I am including code for completeness but I can confirm that this code works for me on localhost and other servers I have worked on.

PHP

if(isset($_FILES) & !empty($_FILES)){
  $name = $_FILES['pictureimage']['name'];
  $size = $_FILES['pictureimage']['size'];
  $type = $_FILES['pictureimage']['type'];
  $tmp_name = $_FILES['pictureimage']['tmp_name'];
  $max_size = 10000000;
  $extension = substr($name, strpos($name, '.') + 1);
  if(isset($name) && !empty($name)){
    if($size<=$max_size){
      $location = '../images/';
      $filepath = $location.$name;
      if(move_uploaded_file($tmp_name, $filepath)){

HTML

<input type="file" name="pictureimage" id="pictureimage">

What am I missing? Why would the form continue to upload to /tmp instead of the upload_tmp_dir that I set?

Rent Charter Buses Company
READ ALSO
Access a file outside of root/htdocs on windows in PHP

Access a file outside of root/htdocs on windows in PHP

How can i access a file outside of htdocs folder on windows? I have a config file outside of my root (htdocs) folder, in which i want to save off the configuration for my database connection, but when i call it, it says no file found

142
Why isn&#39;t my php json_encode not serializable with .responseJSON in alamofire?

Why isn't my php json_encode not serializable with .responseJSON in alamofire?

I'm having some trouble with serialization on a JSON response on my iOS app from my server, its a PHP back-endMy app sends a post request with the appropriate parameters, validates them, puts the results in an array, and encodes it in

106
Hide HTML code when printing in a textbox

Hide HTML code when printing in a textbox

I'm currently storing a few descriptions in MySQL database that includes some html coding (br, li, etc) when I retrieve it works great (if it is on php) but I am trying to retrieve it within a textbox and I'd like to hide the code

148