Link to home
Start Free TrialLog in
Avatar of Drace
DraceFlag for Canada

asked on

Uploading file to Fedora php server creates empty file

Dear Experts,

I looked at : file upload script uploads empty file (https://www.experts-exchange.com/questions/23060161/file-upload-script-uploads-empty-file.html)

but I still have the same problem.. uploading a File creates the file but doesn't fill in the data.

I gave (on my code) ownership of the folder to Apache and did a chmod 755.

I looked at my php.ini:

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = /tmp/

; Maximum allowed size for uploaded files.
upload_max_filesize = 12M


Yet it's still not working.. I moved the code from another server (so I know my code works) and even with the test code I got from the other question, I'm not getting any close..

how do I upload the file so it actually fills the data?
Avatar of alexbumbacea
alexbumbacea
Flag of Romania image

You should check if SE linux is disabled
http://www.crypt.gen.nz/selinux/disable_selinux.html
Avatar of Nitroware
Nitroware

Yes, many times have I been killed by SE Linux.  Defiantly check that first.

Other Questions:
1) How is this Data being uploaded (Flash, HTML form, java, etc)
2) Can you post the PHP code that is handling the upload
3) Can you post the code if it is HTML, especally the "<form" tag
4) Is PHP safe mode on? (in phpinfo();)

That would be very helpful.  I have has this issue before I just cant remember what the issue was.
Avatar of Drace

ASKER

SElinux is disabled, i checked
Avatar of Drace

ASKER

I used the code from the other question.. which claims that it works.. and I think it does.


<?php
if (isset($_FILES['file'])){
        $file = $_FILES['file'];
        move_uploaded_file($file['tmp_name'],$file['name']); }
?>
<form method="POST" enctype="multipart/form-data"><input type="file" name="file"><br><input type="submit" name="submit" value="Upload">
</form>

Open in new window

Avatar of Drace

ASKER


Hi,

I also checked for Php safe mode:

safe_mode => Off => Off


I still need help on this!
Avatar of Drace

ASKER

Here's my SElinux file:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#      enforcing - SELinux security policy is enforced.
#      permissive - SELinux prints warnings instead of enforcing.
#      disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#      targeted - Only targeted network daemons are protected.
#      strict - Full SELinux protection.
SELINUXTYPE=targeted
Have you enabled errors via the following:


error_reporting(E_ALL);
ini_set('display_errors', '1');

Open in new window

Avatar of Drace

ASKER


Hi,

Just added the code and I still don't get any errors...

Looked at the error_log file and its not showing errors.

What else can I try?

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

if (isset($_FILES['file'])){
        $file = $_FILES['file'];
        move_uploaded_file($file['tmp_name'],$file['name']); }
?>
<form method="POST" enctype="multipart/form-data"><input type="file" name="file"><br><input type="submit" name="submit" value="Upload">
</form>

Open in new window

Avatar of Drace

ASKER

I'm still trying to get this to work on my server.

So far all the solutions offered didn't solve my problem.

How big is the file?
Take a look at this:
i was having difficulty with the upload_max_filesize , if u set the max file size lesser than the php setting then ur script to report error will only work till this difference between ur max set file size and the php set max size .Hence if the uploaded file exceeds the php max file size then php end abruptly without a trace of error that is it behaves like no file is uploaded and hence no error reported .Sure if uploading a file is optional for a form then a user who uploads larger file will get no error and still the form will be processed only without the file.
File uploads may create error information that is useful.  Please try this:

var_dump($_FILES);

And then refer to the man pages here:
http://us3.php.net/manual/en/features.file-upload.php
http://us3.php.net/manual/en/features.file-upload.errors.php
http://us3.php.net/manual/en/features.file-upload.common-pitfalls.php

An example of how to do a file upload is available here:
http://us3.php.net/manual/en/features.file-upload.post-method.php

Please look that information over (all of the moving parts are important) and post back with any questions.  Best regards, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Standing by.  Best to all, ~Ray
Avatar of Drace

ASKER

Hi Ray,

ok, I'm trying this out and here's what I got so far:


Results: File Upload

ERROR uploads/pn.txt NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND


pn.txt is a simple notepad file I tried uploading.. I'll try anything as long as you give me steps to follow!

Let me know what I should do next.. thanks!

- Drace
Avatar of Drace

ASKER

helped me determine the error, and through the error_log I was able to solve the issue... BIG THANKS for the help !!!
Thanks for the points!  Best of luck with your project, ~Ray