I have a site for media conversion where users can upload video, audio or image files and it is converted in to 3 popular formats. Conversion script works fine but I am having some issues with the tmp directory where the files get uploaded to. I have tried 2 scenarios I am fine with either but neither works and it seems to me to be permissions related but I can seem to fix the problem.
I am working locally right now while I work out the kinks.
Scenario 1:
File is uploaded to default local tmp directory (C:\WINDOWS\tmp) - works fine
Attempt to run conversion script using tmp file that was uploaded and it doesn't work - run from command line works perfectly fine though
Scenario 2:
File is uploaded to directory I have given IIS_IUSRS full control of (for testing) and file won't upload - yes the directory is spelt correctly (I changed the upload_tmp_dir value in php.ini)
Both the site the javascript that send the XMLHttpRequest to the PHP file, as well as the site the PHP file itself reside on are IIS sites so I assume the script is being run as IIS_IUSRS.
EDIT: Temp file is no longer being created at all for Scenario 1, can't figure out why I am assuming playing with permission messed something up because the code hasn't changed. I've given Modify to IIS_USRS and USERS to try and get it working again but no luck :( although the error log is still writing to the same folder...weird
NOTE: The "tmp_name" value of the $_FILES variable I am sending still has a value of "C:\WINDOWS\Temp\'filename'" but the file is not there
EDIT: Another new development, it appears it is NOT a permissions issue because I can create a temp file via $temp_file = tempnam(sys_get_temp_dir(), 'Test'); however it obviously does not contain the uploaded data so it does not solve my problem
PHP is ignoring the upload_tmp_dir because of one setting on APPLICATION POOLS.
It's not php-cgi.exe nor php.ini or a permissions issue.
Go to the application pool of the website experiencing the issue:
1. right click
2. select advanced settings
3. scroll to LOAD USER PROFILE and set it to FALSE.
that did the trick for me.
This is less of a problem solved and more of a workaround. The issue seems to be something with the
$_FILES['file']['tmp_name'];
When I echo the contents it looks as I expect however no file appears. So rather than taking advantage of that process that happens naturally, I have had to take a manual approach. What I have done is the following:
create a temp file
$temp_file = tempnam(ini_get('upload_tmp_dir'), 'php');
then add the content from the temp file created during the $_POST request. (which some how are in the $_FILES variable even though the file is not when I look in the directory)
file_put_contents($temp_file, file_get_contents($_FILES['file']['tmp_name']));
the I have my temporary file for processing.
Related
I have been tried many times to move the uploaded image or file in a location and also store the name in database.
All the functions work perfectly in LocalHost, but not on Server.
Neither I can see any thing in the directory of a server not any info of the uploaded file in a database.
I have googled and tried almost every trick to solve the issue. Common solution is to edit the permission of a folder. I did it too but all in vain.
What can be the solution ? What am I doing wrong ? The following code works perfectly if using Local host .
$destination_path ="uploads/";
$target = $destination_path.basename( $_FILES["Upload"]["name"]);
$filename=$_FILES['Upload']['name'];
$filetype=$_FILES['Upload']['type'];
$filetmp=$_FILES['Upload']['tmp_name'];
$images=move_uploaded_file($filetmp, $target);
$attachment = file_get_contents($_FILES["Upload"]["tmp_name"]);
$ins_sql="INSERT INTO wp_reklamation(Vorname,Nachname,Auftragsnummer,name,Upload,Grund,Wunsch,Telefonnummer,Email) VALUES('$vorname','$nachname','$auftrag','$filename','$images','$grund','$wunsch','$telefon','$email')";
Moreover, to send the attachment is also an issue. But I believe if this problem first can get resolved, I can solve that mail problem by using the above parameters . But Ofcourse nothing is selected nor moved in the location and database, then how can mail send the item name or anything else related to it .
Thanks
If the code works fine on localhost but not on your server, the most likely cause of the issue is that PHP file uploads are not enabled on your server.
To enable them, find the "file_uploads" directive in your 'php.ini' file and set it to on:
file_uploads = On
Also make sure that the user running your PHP server has permission to write to the target directory.
This question suggests creating a new group with permissions to read and write to the directory and adding the users for the PHP server and FTP as members, so the directory is still accessible through FTP and the server can write uploaded files to it.
I am building a web application using ExtJS4 and PHP5. There is a part where I upload a photo and as I was testing it locally, I am able to upload photos properly to a folder in the file directory.
After I deployed the file to our server online, I tested it. At first, I was getting a class finfo not found, at it pointed to my upload.php file and and to the line:
$finfo = new finfo(FILEINFO_MIME_TYPE);
Upon googling the problem, I needed to make sure that my php.ini file allowed file uploads. So what I did was I made my own php.ini file in the server and I copy pasted the contents from the php.ini file located in ../MAMP/conf/php5.5.10/php.ini but I got an error that I'm trying to decode an invalid JSON String. I also tried ../MAMP/bin/php/php5.5.10/conf/php.ini but I still get the same error.
I don't understand what's happening. I think I'm copying the wrong php.ini file to my server. I am using Freehostia and we are not allowed to access the php.ini file and it was advised to create my own php.ini file. However, so far, copy pasting my php.ini file did not work. It may be that I'm constructing the file wrong.
It's the fist time I've deployed a site that required a file upload, usually I just work with database CRUD and that works.
I found a PHP Settings Page in the home page. I set the PHP to 5.5 and made sure it allowed file uploading.
I'm having a problem when I try to open files that were generated by my CMS on my windows machine. It has an upload function that saves the file on a given location (it is on my user folder, where I'm supposed to have all the write and read permissions).
All I can see in that folder is a generic thumbnail, the ones generated by windows for each image type, PNGs and JPEGs in this case. I tried to change de image permissions and set it to the current computer user but it doesn't work. And I'm unable to move these files to another location (upload them to the server via FTP).
I wonder if there is a way to change this behavior.
One thing I noticed is that if I copy and paste those files, I can see its contents normally. I know I can do that to each of them and rename, but there are dozens of images in that folder... don't wanna do the same thing everytime I upload a new image.
Update
This is happening only to the images that were moved (I'm using php's move_uploaded_file function, btw), not to the ones that where generated (croped, resized and so on).
It`s happening because Windows keep file permissions of TEMP folder (usually c:/windows/temp) when moving a file.
To prevent it you need to change "upload_tmp_dir" in "php.ini" to your server directory or set wide permissions to your windows temp folder.
You probably have an error in some php file which is preventing the image from being displayed correctly.
What i would do in order to detect the problem is to comment out the header() calls in the php file responsible for displaying the image and see if there is any output other than the image data.
Inspect the whole output, it only takes a character to break everything, so check if there are no blank lines at the top or bottom of the output. And in case you have an error log, consult that, it will help you trace the problem quickly.
When i have this problem, it's usually a notice or a warning showing up during the process of the image generation, and if you haven't disabled errors from being output to the screen, the notice text will be considered as part of the image data which makes the browser unable to interpret your image.
If you'd like i can take a look closely for you but i would need to see what you are doing in that php file to be able to tell you for sure.
I have a couple of scripts that worked fine on another server.
Now that I have moved everything on to a new server, the file does not appear in the destination folder. The strange thing is that move_uploaded_file returns true.
Also, I printed the post data and there is no error.
Can you guess what's possibly going on. The files I am trying to upload as a test are very small ( 10 kb).
The move likely succeeded, check the following:
You don't have access to view the file.
Use chmod("/path/to/file.ext", 0755); to add view rights for the ftp user.
You moved the file to an location that doesn't store the file. /dev/null
You're looking in the wrong folder. Did you use a full path?
The file is removed shortly after the move.
In my case, Total Commander, used as an FTP client, truncated output to 10000 files in directory. When I connected via SSH using WinSCP I was able to see all ~14000 files in the directory.
I'm running PHP 5.2.6 on a Windows Server 2003 Enterprise box. IIS is set to deny anonymous access and use Integrated Windows authentication.
I'm using a PHP script to save a file uploaded from a web form. The file is uploaded to a temp folder, the script creates a file name and path depending on other variables from the web form, and then the script uses PHP's move_uploaded_file() to move the temp file to the final location. All that works fine. In short, people are uploading files so everyone in the group can see them and the files are organized by the script.
My problem is that the file in the final location has odd permissions. It is not ending up with permissions from either the temp location or the final location. Both the temp location and final location have the same permissions: full rights for owner and administrations; read and read/execute for 2 specific AD security groups. The final file ends up with only: full rights for owner and administrations. So while the admins and the original uploader have no problem viewing the file, all others in the group get "permission denied" when trying to access it.
Any ideas or suggestions will be greatly appreciated! Thanks!
from the php page on move_uploaded_file (nb: this worked for me):
For those using PHP on Windows and IIS, you SHOULD set the "upload_tmp_dir" value in php.ini to some directory around where your websites directory is, create that directory, and then set the same permissions on it that you have set for your websites directory. Otherwise, when you upload a file and it goes into C:\WINDOWS\Temp, then you move it to your website directory, its permissions will NOT be set correctly. This will cause you problems if you then want to manipulate that file with something like ImageMagick's convert utility.
This seems to be an issue with the move_uploaded_file() function:
http://us3.php.net/move_uploaded_file
Take a look at the comments below, take note of Florian's comment about copy().
Would copy() solve the issue?:
http://us3.php.net/manual/en/function.copy.php