I have created a website where you can upload pictures and the pictures get saved on a server. I had a problem before where the information gets saved in the database but the file wont get saved on the server, I then changed the file rights to 777, which allowed me to upload files to the server. Now I tried uploading a file from another computer but I get the same problem as before. Information gets saved in the database but no file gets uploaded to the server. Anyone got any idea what the problem might be?
You need to check which is the error that returns when you try to upload the file.
Check on the Apache log (or the log of the web server that you use) to see what is causing the issue.
If you are not on a live enviroment (production) or a staging environment (uat), you could enable the error reporting by enabling on the runtime configuration (php.ini) or adding the following lines on your code:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
Here is a good example to follow to implement a file upload.
Related
I have a web app built with angular and PHP that has been established and running since 2016. There is a file upload feature that will upload a file from client-side app to a directory on the server. I noticed the upload is no longer working. Nothing has changed on our end with the configuration of server/hosting or front-end application. The directory still exists and can successfully list files from the front. I get an internal server error when trying to upload with the code below. Very simple example and nothing to indicate this code no longer works. I have file-uploads = on in the php.ini file. It is hosted on GoDaddy. I have checked the error logs and can see that the request is failing but with no detail. Is anyone aware of what may be causing this? I can provide more detail, if thought necessary.
<?php
$target = '../images/attorney_photos/'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $target);
print('/assets/images/attorney_photos/'.$_FILES['file']['name']);
?>
If your file upload is on then check for
upload_max_filesize
and
post_max_size
in your php.ini file and also if you want to upload more than a specific limit each request, then check
max_file_uploads
to be more than files you want upload.
Also it's better to use a tested library for upload your files. you can search for codeguy/upload in packagist and install it with composer for advanced usage or if you no need lots of options you can download this file from github that is so simple, easy to use and well written.
I hope this helps :)
login to plesk administrator panel then goto Domain->Website->PHP Settings
Change upload_max_filesize from "2MB" to "16MB"
Save and try uploading again.
I have a created a project in HTML/PHP and I am trying to upload everything to the server. I am not that familiar with servers other than the fact that your first page must be an index.php/htm file and that everything goes in the public_html folder. I am using MVC(codeigniter) so adding it to the server doesn't seem so straightforward. I have attached an image of my directories, the first file when viewed locally is the controller class which is home.php inside /application/controllers. If I just drag everything to the server as is, then I receive a 500 Internal Server Error. Can anyone help me fix this please?
The problem with a 500 internal server error is that's it's a generic message.
Try checking:
File / folder permission (No files or folders should be set to 777, 755 should be the maximum permissions setting.)
If you're using short tags: short_open_tag=On in php.ini
Incorrect syntax in .htaccess file (Try removing - test - recreate)
check error.log for more detailed information.
Hope any of this helps, I'll keep an eye on this topic.
If I write a php file on /var/www/html, the php file works well. For example a simple script in which I print phpinfo().
If I write a php script on my computer, then drag it to my server using Filezilla, it uploads well - to the extent that there are no error messages, and I am able to move the php script to /var/www/html.
However, when I try to access the file through my server's ip address (i.e. [server ip]/file.php - the page displays this error:
The 45.55.136.85 page isn’t working
45.55.136.85 is currently unable to handle this request. HTTP ERROR 500
For more information:
I write the php file in gedit encoded using Current Locale UTF-8 Line Ending Unix/Linux. And I have tried the three available transfer settings with no success Auto/Binary/ASCII on Filezilla
I upload files using FTP over TLS using Filezilla.
I have installed a LAMP stack.
This is a file permission problem, to solve this go to your Cpanel and under metrics section go into the errors
Most of the time you will find such error because of assigning extra permissions(write and execute) to the Group or World.
To solve this just withdraw the file permission and follow the below permission pattern.
Mode User Group World
Read check check check
Write check uncheck uncheck
Execute uncheck uncheck uncheck
I use PHP version 5.3.19, Windows Server 2008 R2 Standard SP 1 and Internet Information Services (IIS) 7.5.7600.16385.
My problem:
I can't change the PHP error log file location.
When I try that and restart the IIS service, my web application cannot be opened:
Browser says 500 - Internal server error.
I tried everything.
I checked the error logs of Windows and the IIS error log.
Nothing! Is this possible?
I was able to change the locations of the PHP session data folder and the PHP upload temp folder, no problem. (I created a folder, C:\myapplication\mycompany\temp, and gave this new folder all the necessary rights, so the IIS IUSR can do everything.)
So: The new locations of the PHP session data folder and PHP upload temporary folder work after restart of the IIS service! That's fine!
But I cannot change the location of the PHP error log file. Why?
It is the same new Windows folder having the ultimate rights.
I tested a little bit with different text files.
I created new and empty log files, tested with the original PHP error log file from C:\Windows\Temp. Nothing. And I really restarted the IIS service after every change of the php.ini file. But in the end: The browser says 500 - Internal server error when browsing the web application.
So, what can I do? I don't understand what's wrong.
You may be setting the error logs in file php.ini.
Try setting it at runtime with something like:
ini_set('display_errors', 'on');
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
ini_set('error_log', "C:\php\error.log");
That way, you should see the error message on screen, it there is one.
I have a php script which uploads images to a temporary folder on the server.
This works on my local computer with the local (virtual) server. (wampserver).
However, on the production server (linux) I cant get it working.
Everything is loading as it should, except for that the file doesn't show up on the server.
My Q is, is there anything I should think about when moving to a production server with uploading images or files?
I have set permissions on the folder where the images are supposed to go to 777 and also the php-code which uploads them to 777.
Thanks
is there anything I should think about
when moving to a production server
with uploading images or files?
Yes.
Error handling.
You have to keep in touch with PHP error reporting in general
and properly handle $_FILES['name']['error'] variable in case of upload.
These two sources will provide you with sufficient and precise information on any error occurred.
I highly recommend to you first to read this article before setting 777 permission on the server. Besides, there are different ways of uploading files are shown, so I think you will solve your problems after reading this article. Good luck
I know this question is old but I doubt any of the answers given are correct as I have had this exact problem and it turned out to be that when I created the php form I forgot to add this line to the form tag enctype="multipart/form-data" so processing the form on my local machine worked fine but when I tried to upload an image to the production server with the form it wouldn't process the image file, it would process all the other data from the form just not the file that needed to be uploaded. After I added the line above it worked fine.