Jump to content

Missing files after upload


BigShieldsy

Recommended Posts

Hey guys hopefully someone can help here.. This is the code that i am using and for a newb this seems to be working ok with only minor issues at the moment.. However i have one major issue that the file that has been upload disappears and will not appear in the folder location.

<? ini_set('display_errors', 1); error_reporting(E_ALL); include '../Docs/db.php'; $home_team = $_POST['home_team']; $away_team = $_POST['away_team']; $fixture = $_POST['fixture']; $team = $_POST['team']; $score = $_POST['score']; $allowedExts = array("mp4", "ogg", "webm"); $temp = explode(".", $_FILES['video']['name']); $extension = end($temp); if(isset ($_FILES["video"])) { $name = $_FILES["video"]["name"]. "<br/>"; $type = $_FILES["video"]["type"]. "<br/>"; $size = $_FILES["video"]["size"]. "<br/>"; $tmp_name = $_FILES["video"]["tmp_name"]. "<br/>"; /*echo 'The file name is: ' . $name . '<br/>'; echo 'The file type is: ' . $type . '<br/>'; echo 'The file extension is: ' . $extension . '<br/>'; echo 'The file size is: ' . $size . '<br/>'; if ($size < 25000000){ echo 'The file size is: ' . $size . ' is correct <br/>'; } if ($extension == 'mp4'){ echo 'The file size is: ' . $extension . ' is correct <br/>'; }*/ if (($extension == 'mp4') && ($size < 25000000) && in_array($extension, $allowedExts)) { if ($_FILES['video']['error'] > 0) { echo "Return Code: " . $_FILES['video']['error'] . "<br>"; } else { echo "Upload: " . $name . "<br>"; echo "Type: " . $type . "<br>"; echo "Size: " . ($size / 1024) . " kB<br>"; echo "Temp video: " . $tmp_name . "<br><br>"; $temp_video = 'Videos/' . $name; echo "temp_video name: " .$temp_video. "<br/>"; $sql = mysql_query("SELECT * FROM highlight"); $result=mysql_query($sql); $rows=mysql_fetch_array($result); $location = $rows["location"]; if(($location == "") || ($location != $temp_video)){ echo 'The file name is: ' . $name . '<br/>'; echo 'The file type is: ' . $type . '<br/>'; echo 'The file size is: ' . $size . '<br/>'; move_uploaded_file($tmp_name, "/home/user/public_html/MembersArea/Highlights/Videos/" . $name); echo "Video Stored in: " . "Videos/" . $name; $location = "Videos/" . $name; echo 'The location of the video is: ' . $location; /*$sql1 = mysql_query("INSERT INTO highlight (location, team, posted) VALUES ('$location', '$team', now())") or die (mysql_error()); echo '<br /> Video location added to database <br />';*/ } else{ echo "The File named: " .$name . " already exists. <br>"; } /*$location = "Videos/" . $name; $sql = mysql_query("INSERT INTO highlight (location, team, posted) VALUES('$location', '$team', now())") or die (mysql_error());*/ } } else { echo "Invalid video"; } }?>

 

hope someone can help with this one as to where my file could beThis is a screen shot of the code running last..

 

 

post-164592-0-49900600-1399230194_thumb.png

Link to comment
Share on other sites

This may be why you're getting the mysql errors:

             $sql = mysql_query("SELECT * FROM highlight");            $result=mysql_query($sql);            $rows=mysql_fetch_array($result);

mysql_query is being called twice and the result of the first call is stored in $sql and then you call mysql_query again passing the result of the first call.

 

Try (I'm assuming you made database connection in db.php) :

            $sql = "SELECT * FROM highlight";            $result=mysql_query($sql);            $rows=mysql_fetch_array($result);

This may or not may be related to the file disappearing after upload, but most likely it's the mysql errors you've come across.

 

Try setting a return variable to the move_uploaded_file function to see if it's success or not (true or false). It returns true on success or false on fail.

$status = move_uploaded_file($tmp_name, "/home/user/public_html/MembersArea/Highlights/Videos/" . $name);if($status){    echo 'Uploaded';}else{  echo 'Uploaded Failed';}
Link to comment
Share on other sites

Hey don thanks alot in getting back to me i have updated the code with an if statement and have now since found out that the move_upload_file is returning a false.. The sql issues have since been resolved since the update as well.

Edited by BigShieldsy
Link to comment
Share on other sites

$location = "/home/bellg980/public_html/MembersArea/Highlights/Videos/" . $name; echo 'The new location of the video is: ' . $location; if(move_uploaded_file($tmp_name, $location)) { echo "Video Stored in: " . "Videos/" . $name; /*$sql1 = mysql_query("INSERT INTO highlight (location, team, posted) VALUES ('$location', '$team', now())") or die (mysql_error()); echo '<br /> Video location added to database <br />';*/ }else{ echo 'Error moving file'; }

 

This is the new if statement being used. However now getting 'Error moving file' :(

Link to comment
Share on other sites

Everything seems okay... Make sure the $location path is correct and that permission is allowed to move files to that directory. Check your server error logs to see if an error is outputted when attempting to run the above script.

 

If everything is good with the code and the path is correct, then it may be a 'permissions' problem.

Edited by Don E
Link to comment
Share on other sites

I am currently still having some issues with page moving the file over to my directory and still giving me the error message i had set up.. I am currently in contact with the hosting company who are looking into this issue.. any other information will still be very much appreciated ;)

Edited by BigShieldsy
Link to comment
Share on other sites

This is the response from my hosting company can any one shed any light on what they are talking about:"Script is not working because during the upload it tries to create /tmp/phpwQFTYv on server's end, yet it can't be created as it's not permitted, due to security reasons. So basically previous assumption was correct, tmp directory which your script creates should be created within your account's home directory, not entire (shared) server's which is the reason it doesn't work. Your script should grab file from temporary directory which is in your public_html folder."

 

Thanks

Link to comment
Share on other sites

After discussing at length with the hosting company they are saying that i have to make some changes to my script in order for it to upload the file to the Videos folder..They say that i have to make the function use my home directory (public_html) instead of main server's tmp directory

 

and now i feel like a man left in the desert with no water lmao..

 

Does any know if there is a possible tutorial on how to do this??

Link to comment
Share on other sites

It means the script is looking in the wrong directly for the uploaded file. It is looking in the /tmp directory of the server itself. The tmp folder the script should look for, for uploaded files is in your 'home' directory which I assuming is somewhere in here: /home/bellg980/public_html/. Could be in: /home or /home/bellg980 or /home/bellg980/public_html/.To see exactly where PHP is looking for tmp files, go into your php.ini file and look for this to see the path for the PHP tmp folder for your account on the server:

 

upload_tmp_dir = path should be here to tmp folder

 

For example, it should look something like this:

 

upload_tmp_dir = /home/bellg980/tmp

Use the file manager for your account to see where the tmp folder is and if the above is not set to the correct tmp folder, set it to whatever the tmp folder is for your account.

 

It's possible this setting is set to something else for you causing you to experience what you're experiencing. From what I understand when I use to be on a shared hosting environment, everyone on the server has their own php.ini file. So in other words, you cannot be using a 'global' one where the same settings apply to everyone on the server. In other words, this may be an issue with your php.ini file. (Maybe not though)

Edited by Don E
Link to comment
Share on other sites

Hey don you should work for this hosting company haha waste of bloody time had more info from you than all of them put together ha..I have made up a new folder called /tmp1 along with a new file called php.ini (inside this file i have added the line 'upload_tmp_dir = /public_html/tmp1') also inside the .htaccess file i have added this line: 'SetEnv PHPRC /public_html;' as per instructions from the hosting company...

 

public_html is apparently is my root folder /home/bellg980 is invalid :S

 

I am unfortunately still getting the same error message. Have i done something wrong or missed something out..P.S.i never had a php.ini file to start with i had to make one in my public_html folder.

Edited by BigShieldsy
Link to comment
Share on other sites

What hosting company is this? Just wonderingWhen you log into your account, are you presented with something like a cPanel? This is a demo of a cPanel: http://x3demob.cpx3demo.com:2082/cpsess8155144553/frontend/x3/index.html?post_login=72861321213447

 

What else you can try to see what is going on is by creating a php file called something like phpinfo.php and inside the file, you have this:

<?php     phpinfo();?>

Upload that to the directory where your website files are and go to it by going to your browser and typing in: mysite.com/phpinfo.php (mysite would be your site domain).

 

You should get/see information regarding your PHP like the version you're using etc. Also it should tell you what(meaning what php.ini file is loaded because its possible you may have a couple or so) and where your php.ini configuration file is located at.

 

IF you don't have access to a php.ini file then it looks like the one you're using is the 'global' one for the server you're on. I'm a bit surprise by that since usually(and in my case when I was on shared server), everyone had their own php.ini file. This HAS to be because for example, it doesn't make sense that everyone is using the same php.ini file when for example, one person on the server doesn't need to increase the POST max size while another person might need to increase to allow POST data of more than the default set size which I think is 2M (MB).

 

Link to comment
Share on other sites

Hi Don the hosting company are from your side of the pond lol. Its an American company called Hosting24.Yes after log in i am presented with a option to sign into my cpanel where i have made and set up my database tables through myphpadmin.

 

I have now uploaded the new phpinfo page and can be found at www.bellgroveafc.com/phpinfo.php Hope that helps a little i have also included the .htaccess page along with the new php.ini file.htaccess

SetEnv PHPRC /public_html

php.ini

upload_tmp_dir = /public_html/tmp1 (using tmp1 to tell the difference between my own tmp folder and the server's tmp folder.)

Link to comment
Share on other sites

i was told from the hosting company that /home/bellg980/public_html was equal to just using /public_html/I will give it a try though no harm in it i guess.

 

UPDATE!!

After changing the paths i am still in the same situtation where nothing in the phpinfo has been changed..The webpage to upload a video file is: www/bellgroveafccom/MemebrsArea/Highlights/highlight_upload.php(if uploading you will require a mp4 file less than 20mb)(3-5 mins video will be fine)The upload script will run and appear with echo's through out details values stored in the variables being used up until it gets to the move_upload_file() function and will fail with the error message being printed

Edited by BigShieldsy
Link to comment
Share on other sites

From the looks of your PHP info out put, the php.ini file ithat is loaded and being used s located at: /usr/local/lib/php.ini

 

This is a global one most likely, meaning everyone under that server is using that php.ini file. So in other words, everyones' tmp directory where uploaded files go to, is the same.

 

I went to hosting24 and I'm having a chat with them via live webchat and it appears that for shared hosting accounts, people are not allowed to edit the php.ini file and everyone is using the global one. So in other words, everyones php settings(configurations) are the same.

 

Here's part of the chat:

15:40Elvin S.: Hello and welcome to Hosting24.com, how may I help You?
15:42Don: Hi. I was wondering on the shared hosting plan, will I be able to edit the php.ini file for my account incase I need to change any settings like the POST max size, etc?
15:42Elvin S.: Unfortunately you will not be able to edit it.
15:42Elvin S.: You would need VPS in order to access php.ini
15:46Don: Oh ok, so basically all php settings are the same for shared hosting accounts. Are file uploads allowed with shared host accounts?
15:47Elvin S.: Yes, the settings are the same
Since file uploads are allowed AND you're not allowed to edit the php.ini file to your specifics, then one or two(or more lol) things could be causing our problem: the video you're trying to upload is TOO big in size which exceeds the php allowed size for file uploads, OR, IF the video you're uploading doesn't exceed the php values set for file upload sizes etc and is actually being uploaded to the server, then when moving the file with move_upload_file function, the path is not correct. I see that in the first snippet of code you posted, you used this for the destination:
move_uploaded_file($tmp_name, "/home/user/public_html/MembersArea/Highlights/Videos/" . $name); //user most likely has to be your user account name: bellg980
Instead try: move_uploaded_file($tmp_name, "/home/bellg980/public_html/MembersArea/Highlights/Videos/" . $name);
Good luck.
Edited by Don E
Link to comment
Share on other sites

Hi don, I have tried that in the past still with the same outcome...

 

did they not tell you that you are not allowed to move a file from the tmp folder to a folder that is created into your own folder in your account.. You are allowed to move any file form with in your account.. Is it getting the file uploaded to a location in my account that i need to crack first but he is saying that is not allowed then i do not understand how i ment to move the file..Let me see if i have the correct..

The file is being uploaded from a form using the muiltipart/form-data and POST method with an action to go to upload_highlight.php(the script).. Now should the file be stored in a temperary folder with in the server?? before being moved using the move_uploaded_file()function to a location with in my account i.e /home/bellg980/public_html/MembersArea/Highlights/Video/....

 

If this is correct then this is the problem as i know this is not allowed to move files from that location on the server to a location in my own account.. You are only allowed however to move files from one location in your own account to another in your own account.. (now if you are allowed to do this then how am i ment to change the location of the temp folder so that it is inside my account, if i am not allowed to use a php.ini file to change anything ??? )

Edited by BigShieldsy
Link to comment
Share on other sites

Run this and see what it shows:

<?phpecho 'PHPRC=' . getenv('PHPRC') . '<br>';echo 'PHPRC=' . apache_getenv('PHPRC');
That will tell you if the environment variable is being set correctly.
Link to comment
Share on other sites

Since the phpi.ini file is the same for everyone and upload_tmp_dir in the php.ini is set to /tmp, either it means the tmp folder of the server or the tmp folder for your account, I'm not sure. If it means the tmp folder for the server, then no you cannot move a file from that location to your account, like the person you chatted with said:"Script is not working because during the upload it tries to create /tmp/phpwQFTYv on server's end, yet it can't be created as it's not permitted, due to security reasons. So basically previous assumption was correct, tmp directory which your script creates should be created within your account's home directory, not entire (shared) server's which is the reason it doesn't work. Your script should grab file from temporary directory which is in your public_html folder."

 

If it means the tmp folder for your account then, then make sure you have a tmp folder there which I'm sure you do.

 

Have you tried using a smaller video size or how about trying to upload an image? This problem could be maybe from using a file size that's bigger than what's allowed in the php.ini settings. Try uploading an image that's fairly small in size and see if it gets uploaded and moved to the directory.

Link to comment
Share on other sites

in any of the php pages or the upload_highlight.php page sorry i am new to this stuff with php.

Inside any PHP file in a directory affected by the changes you made to .htaccess. The point is to make sure that the environment variable in .htaccess is being set. You need to verify that the environment variable is being set, then verify that your custom php.ini is being loaded, then verify that the changes are taking place.This describes the runtime configuration for PHP:http://www.php.net/manual/en/configuration.phpMany PHP options can be changed at runtime by using something like the ini_set function. The upload_tmp_dir option is not one of those, because once your code is actually running, and you're calling ini_set, the upload has already taken place and the file is already on the server. The upload_tmp_dir option is PHP_INI_SYSTEM, which means the only place you can change it is either php.ini or httpd.conf.

Have you tried using a smaller video size or how about trying to upload an image? This problem could be maybe from using a file size that's bigger than what's allowed in the php.ini settings.

You can also just check the error code, it will tell you what the problem is. If it's too big, it will tell you that. If the file couldn't be written, it will tell you that too.http://www.php.net/manual/en/features.file-upload.errors.phpIf it did write the file, you can get the path to it from tmp_name and use the is_readable function to test if you can read the file. If it uploaded and you can't read the file, or it couldn't write the file at all, then the reason is that permissions on the temp directory do not allow you to use it, and the fix is to change the temp directory.http://www.php.net/manual/en/function.is-readable.php
Link to comment
Share on other sites

Hi Don thanks for explaining it for me it confirms what i was think however having added the two lines of code i am getting this message from them on the page:PHPRC=/home/bellg980/public_htmlPHPRC=/home/bellg980/public_htmldoes that mean that my location of the /tmp folder should be inside there?What do they mean??

 

Thanks

Link to comment
Share on other sites

That means that the environment variable that you set inside .htaccess worked. So, theoretically, it should be picking up a php.ini file that you have inside your public_html directory. So, create a phpinfo page to test that. Make the change to upload_tmp_dir inside php.ini and then open your phpinfo page to make sure it's picking up the changes.

Link to comment
Share on other sites

Make sure you've created the directory that you are pointing to. You might have to contact your host again. Give them the contents of the .htaccess file, the contents of your php.ini file (and tell them where you saved it), and a link to the phpinfo page.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...