otuatail Posted October 9, 2015 Share Posted October 9, 2015 <?php require("../secure/SecureFunctions.php"); session_start(); Session_Init(); if(!isset($_SESSION["Pk"])) { header('Location: index.php'); exit; } $Pk = $_SESSION["Pk"]; if(KeyCheckX($Pk)== 0) { header('Location: index.php'); exit; } $User = $_SESSION["Uk"]; $Shelf = 0; connectDB(SUGARCAIN); $Meg = 1000000; $detials = $_POST["details"]; $FileSize = $_FILES["file"]["size"]; if (/* (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/vnd.ms-powerpoint") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation") || ($_FILES["file"]["type"] == "application/msword") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") || ($_FILES["file"]["type"] == "application/vnd.ms-excel") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") || ($_FILES["file"]["type"] == "audio/mpeg") || ($_FILES["file"]["type"] == "text/plain") ) && */ ($FileSize < 20 * $Meg)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { $real = $_FILES["file"]["name"]; // $GetName = ServerName($_FILES["file"]["name"]); $x = explode('.',$real); $GetName = time() . "." . $x[1]; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $GetName); $path_parts = pathinfo($GetName); $FileName = $path_parts['basename']; $hex = dechex($FileName ); $date = date('Y-m-d H:i:s' , $FileName); ConnectDB(SUGARCAIN); $sqlFtp = "INSERT INTO library (User,Shelf,ShelfMarker,RealName,Description,ServerName,Submitted,FileSize,Ref) VALUES ('$User',$Shelf,'03c2e7e41ffc181a4e84080b4710e81e','$real','$detials','$GetName','$date',$FileSize,'$hex')"; $query = mysql_query($sqlFtp); // // $result = mysql_affected_rows(); mailtoupload("Upload",$_FILES["file"]["name"],$_FILES["file"]["size"],$_FILES["file"]["type"],$detials); header('Location: acknowledge.php'); } } else { if($_FILES["file"]["size"] > 7000000) { mailtoupload("FAILED UPLOAD",$_FILES["file"]["name"],$_FILES["file"]["size"],$_FILES["file"]["type"],$detials . " Size"); header('Location: failure.php?id=1'); } else { mailtoupload("FAILED UPLOAD",$_FILES["file"]["name"],$_FILES["file"]["size"],$_FILES["file"]["type"],$detials . " Bad Type"); header('Location: failure.php?id=2'); } } ?> I created a cloud based system long before Microsoft. This worked fine on a server for 8 years. Recently I have subscribed to another company and my website is now there. When I upload a file myfile.docx it ends up on the server as 1444374830.docx I used the unix stamp time() to make it unique and keep the extension On the new server it is now 1444374830.desmond I have to download it and change the extension to .docx but the downloaded file is unusable. Can someone tell me what is wrong with the code or is it a server issue. $GetName = time() . "." . $x[1]; should end up as 1444374830.docx And the uploading code page Hope this can be fixed as I am using the site as a versioning backup of my word documents. Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 9, 2015 Share Posted October 9, 2015 $real = $_FILES["file"]["name"]; // $GetName = ServerName($_FILES["file"]["name"]); $x = explode('.',$real); $GetName = time() . "." . $x[1]; If $real is "myfile.desmond.docx" then you will get desmond in $x[1] Quote Link to comment Share on other sites More sharing options...
otuatail Posted October 12, 2015 Author Share Posted October 12, 2015 No $real is not myfile.desmond.docx and that is not what is on the server. There is no .docx the extension has been removed and replaces with .desmond. I pic a file for example MyStory.docx I get a unix time stamp time() to make the files on the server unique. I end up with 1444374840.docx I am changing the file name on the (unix) server. $GetName It seems that the server has striped the dile extension .docx of and replaced it with my account name on the server giving me 1444374840.desmond. This never happened on the old company which I used this software for over 8 years. It worked for 8 years so it can't be a codeing error unless my php move_uploaded_file() is difrent. Quote Link to comment Share on other sites More sharing options...
otuatail Posted October 12, 2015 Author Share Posted October 12, 2015 No $real is a normal file name MyStory.docx $GetName = 1444374830.docx I replace the left part with a unix time stamp time() I want this to be the replacement name on the server. This worked when I had my website hosted on fast hosts for 8 years. The server seems to have stripped off my dotx and replaced it with my account name on the server. This is strange behaviour and makes life difficult Quote Link to comment Share on other sites More sharing options...
otuatail Posted October 12, 2015 Author Share Posted October 12, 2015 (edited) move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $GetName); I have just spoken to easy space and they can't understand what has caused this. The only thing they suggest is that it is to do with an older version of PHP. Fast host put me on a modern server a year ago so I don't understand that. Could I rename the file back as the uploaded files are in a subdirectory of the website /upload? They are going to try moving me from php 5.4.45 down to a server php 4.3.9 This can only be around the code above. Has this upload function changed in anyway? Edited October 12, 2015 by otuatail Quote Link to comment Share on other sites More sharing options...
Barand Posted October 12, 2015 Share Posted October 12, 2015 Get the mime type of the updated file and apply the extension according to that value. You are already on an outdated version of PHP, you don't want to move to a worse situation. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted October 12, 2015 Share Posted October 12, 2015 1) what does using var_dump($_FILES["file"]); immediately after the first opening <?php tag (in case some of your code/functions are modifying the value) show? 2) are you sure about the actual php code that's running? a statement like $GetName = ServerName($_FILES["file"]["name"]); could very well account for the symptom you are getting. Quote Link to comment Share on other sites More sharing options...
otuatail Posted October 13, 2015 Author Share Posted October 13, 2015 I wonder is there a forum for people having a nervous breakdown? I could not believe that when I uploaded a file with an extension of .doc or .pdf. The sever would change my extension to .desmond The hosts suggested that I move to a server with an older version of php. In doing so, they messed up the DNS. The server I am uploading to is difrent to the website. Ok what happened. I love writing comedy like only fools and horse’s. There is a completion where by up to 2,000 people will send there comedy’s in (God knows we need good comedy in the UK). I wrote a cloud based system in 2007 before Microsoft. What I did was using the time() php replace the left hand side and keep the extension. That way I can always go back to a previous version. The BBC, ITV and CH4 in there infinite wisdom declared that the name of the file has to be [Surname] . [First name] . Comedy name] . pdf When I fetch the name of the file to upload $_FILES["file"]["name"] I have too many dots. Hence otoole.desmond.caferoyal.pdf using explode and then value[1] ends up with desmond and not pdf. Can I fetch the last value in the explode statement which would guarantee the file extension. Help please Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 13, 2015 Share Posted October 13, 2015 (edited) Two options: $file = 'otoole.desmond.caferoyal.pdf'; $fileNameArray = explode('.',$file); $idx = count($fileNameArray) - 1; print("<p>Count:</p><p>".$fileNameArray[$idx]."</p>"); //a little wordier, but possibly easier to read print("<p>End:</p><p>".end($fileNameArray)."</p>"); //quicker, with less typing This will return the file extension, assuming no one adds another dot and characters after the .pdf in the file listing. Edited October 13, 2015 by maxxd Quote Link to comment Share on other sites More sharing options...
Barand Posted October 13, 2015 Share Posted October 13, 2015 3rd option: $fname = 'otoole.desmond.caferoyal.pdf'; $ext = strrchr($fname, '.'); echo $ext; //==> .pdf When I fetch the name of the file to upload $_FILES["file"]["name"] I have too many dots. Hence otoole.desmond.caferoyal.pdf using explode and then value[1] ends up with desmond and not pdf. Which is what I pointed out to you in reply #2 If $real is "myfile.desmond.docx" then you will get desmond in $x[1] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.