Results 1 to 1 of 1
  1. #1
    Greescom is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Default Please critique my solution to retrieving variables out of php.ini

    I have created a local php.ini file that has variables relating to max upload filesize for my file uploading applet. I want to load these variables into my applet so I can check it against the files to be uploaded.

    I have coded a solution that is fully working but I can't help but think it should be easier than this. I want to write code that is as compact as possible while still maintaining readabiliy.

    php.ini file:
    Java Code:
    [PHP]
    ; overides standard setting of 8mb max upload
    ; set them both to be the same number!
    
    post_max_size = 60M
    upload_max_filesize = 60M
    Java:
    Java Code:
    //Get max allowed file size from PHP.ini
    try {
    	int postSize = 8;
    	int fileSize = 8; // 8mb is apache default
    	String line;
    	URL urlIni = new URL(getCodeBase() + "php.ini");
    	URLConnection urlConIni = urlIni.openConnection();
    	BufferedReader phpIniOpen = new BufferedReader(
    		new InputStreamReader(urlConIni.getInputStream()));
    	while ((line = phpIniOpen.readLine()) != null) {
    		if (line.indexOf("post_max_size =") != -1) {
    			postSize = Integer.parseInt(line.replaceAll("[^0-9]",""));
    		} else if (line.indexOf("upload_max_filesize =") != -1) {
    			fileSize = Integer.parseInt(line.replaceAll("[^0-9]",""));
    		}
    	}
    	maxFileSize = (postSize < fileSize) ? postSize : fileSize;
    	phpIniOpen.close();
    } catch(Exception e) {
    	statusTa.append("Error - Problems reading php.ini file\n" + e + "\n");
    }
    Last edited by Greescom; 05-17-2011 at 06:01 PM. Reason: Spelling

Similar Threads

  1. Data extraction, pleas help!!
    By bob nash in forum New To Java
    Replies: 1
    Last Post: 05-04-2011, 09:09 AM
  2. Please critique
    By jim01 in forum New To Java
    Replies: 4
    Last Post: 09-24-2010, 04:43 AM
  3. Critique Java Game: Help Me Improve
    By gretty in forum New To Java
    Replies: 1
    Last Post: 07-15-2010, 05:30 AM
  4. Pleas help me
    By Smile in forum Java Applets
    Replies: 2
    Last Post: 04-23-2010, 02:18 PM
  5. New here, pleas help!
    By prairie_hoops in forum New To Java
    Replies: 4
    Last Post: 10-29-2009, 08:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •