Apache2 cant find pdf file in default directory - php

so, I have a setup with apache2, php5, Mysql, etc... everything seems to work alright and I'm using default directory /var/www/html.
I can upload pdfs into directory /var/www/html/uploads, and also display the pdfs uploaded into directory in list of links by using scandir(php method).
I've also checked permissions on the directory, pdf files, and /etc/mime.types.
And ofc, the files are there too. I have also tried naming my pdf files with lower case without any special characters.
The error code is 404 Not found:The requested URL /var/www/html/uploads/cv.pdf was not found on this server. When I try to download the file, by right-clicking link and downloading, i just get a broken pdf that isnt readable. However, the pdf files seem perfectly fine, since when I scp them back to my local computer and read them they're not broken at all.
Any suggestions on why I may be experiencing this error?
All suggestions and help appreciated.

Related

What are possible reasons that HTML download link is failing?

I created a page for users to download certain files. I used the HTML download link to do this as so:
<a download href="/home/Uploads/someDir/someFile.PNG" >View</a>
This worked fine when I was developing on my laptop with WAMP. When I uploaded the code to our Centos 7 Server it did not work. I changed the Uploads, someDir, and someFile.PNG permissions to 777. I also made sure that the file path was correct. But the when the download link is pressed the file icon at the bottom of the screen says "Failed no file".
Maybe I need to do more with the permissions. I know that the folder that the html file is in has restricted permissions, but I would prefer to keep them that way. I do not know how that could cause an issue.
I am looking for debugging tips/possible causes. At this point I am clueless where to look.
The issue with the download not working is simply due to the fact that the path to your file is wrong. My advice on your root directory which is in most cases is var/www/html, create a folder called say somefoldername and manually upload the file to that folder then change the download link to be
View.
"Failed no file" has nothing to do with permissions. The path to your download file has most likely changed when the files were uploaded to the server. You should manually check to see if the file at
/home/Uploads/someDir/someFile.PNG
actually exists. If not you can change the link accordingly or move the download file to the appropriate location.
Another good alternative to solve this error is to put a dot '.' at the beginning of the url:
<a download href="./someDir/someFile.PNG" >View</a>
This way you will not need to indicate the complete url.
And if in the future the url changes, you won't have to modify the url.
In my case it works perfect, I hope it helps you too.
Just check the directory in which you are trying to fetch the file. Your looking file may be not present in that directory. Otherwise, you are using the correct piece of code.
<a download href="~/home/Uploads/someDir/someFile.PNG" >View</a>

PHP - finfo class not found. unable to upload file after deploying site online

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.

Can't open files generated by PHP app on windows

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.

Trouble locating images

I'm having trouble with missing images on my server.
I have been developing a site locally using MAMP for a while and now that I have uploaded it to my server the images cannot be found. Firebug tells me "Failed to load the given URL".
The file structure is the exact same as it was locally and the code is also the same.
The php file trying to load the images is in the site's root folder along with the folder "images".
Here is the file structure: images/models/dreadfinsl1.jpg
Here is the page: http://eoghanoloughlin.net/george/index.php
Can anyone help me? It seems like it would be just one of those stupid problems / simple answers but I'm relatively new to this don't have much experience. It was working fine when I was using MAMP.
Looks like your in the /george/ map on the server, and i assume locally u used www/
try /george/images/models/dreadfinsl1.jpg
else you will have to use full path http://eoghanoloughlin.net/george/images/models/dreadfinsl1.jpg
Try to access an image which is in your server with the help of web browser by specifying absolute path of the image....
Like http://eoghanoloughlin.net/images/models/dreadfinsl1.jpg
If you found any image on the browser, try to display the same image on your index page...
I think specifying the file path is being a problem in your application....

Flash/PHP: Using the AS3 Jpeg Encoder

I am a beginner at both Actionscript3 and PHP, and I'm trying to get Henry Jone's movie clip to jpeg code to work for me, as seen here:
http://henryjones.us/articles/using-the-as3-jpeg-encoder
I downloaded the source and then uploaded the .swf and the .php in the same directory. However, when I click "download your sketch," it downloads the .php file instead of a jpeg.
The .swf I uploaded can be seen here:
http://www.snut.org/storage/scrntest/sketch.swf
I didn't change any of the code from the source I downloaded, so I can't figure our what the problem is. Can anyone help?
Rule of thumb - any time your web server downloads .php files instead of rendering the output of the file it is a good sign that your server isn't set up to handle PHP. You need to tell Apache to use PHP, google around for "install PHP on Apache web server" and that should get you started.
Basically .php files are just text files, so unless you have something telling your web server to treat .php files different from normal text files then it'll just assume the user wants to download the file that's being linked.

Categories