Find the answer to your Linux question:
Results 1 to 2 of 2
I've wriiten a PHP script wich upload three files thru a POST form. Here is the form code: Code: echo "<form method=\"POST\" enctype=\"multipart/form-data\">"; echo "<table>"; echo "<tbody>"; /* Media upload ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401

    PHP upload apparently works, but...


    I've wriiten a PHP script wich upload three files thru a POST form. Here is the form code:

    Code:
    echo "<form method=\"POST\" enctype=\"multipart/form-data\">";
    		
    		echo "<table>";
    		echo "<tbody>";
    		
    		/* Media upload form */
    		
    		echo "<tr>";
    		echo "<td>";
    		echo "  <select name=\"media_to_del\" size=\"20\">";
    		$list = wiew_get_sources&#40;&#41;;
    		foreach &#40;$list as $media&#41;
    			echo "<option value=\"$media\">$media</option>";
    		unset&#40;$list&#41;;
    		echo "  </select>";
    		echo "</td>";
    		
    		echo "<td valign=\"top\">";
    		echo "  Media name&#58; <input name=\"title\" type=\"text\">
    ";
    		echo "  Left video file&#58; <input name=\"lv_source\" type=\"file\">
    ";
    		echo "  Right video file&#58; <input name=\"rv_source\" type=\"file\">
    ";
    		echo "  Audio file&#58; <input name=\"a_source\" type=\"file\">
    ";
    		echo "  <button name=\"media_upload\" type=\"submit\">Upload</button>";	
    		echo "  
    
    ";
    		
    		echo "  <button name=\"media_delete\" type=\"submit\">Delete</button>";
    		echo "</td>";
    		echo "</tr>";
    		
    		echo "</tbody>";
    		echo "</table>";
    		echo "</form>";
    When the page is loaded, a function will call the dedicated routine to performe file upload:

    Code:
    /*
    	   This routine will upload all files needed and move them in the media
    	   repository. This routine requires the following variables&#58;
    	   - $_FILES&#91;'lv_source'&#93;
    	   - $_FILES&#91;'rv_source'&#93;
    	   - $_FILES&#91;'a_source'&#93;
    	   - $_POST&#91;'title'&#93;
    	   
    	   Audio source is not required. The directory will be created under $GLOBALS&#91;'media_prefix'&#93; using the title
    	   specified. Uploaded file will be named&#58;
    	   - LVIDEO.mpg for left video source.
    	   - RVIDEO.mpg for right video source.
    	   - AUDIO.wav for audio source &#40;if any&#41;.
    	 */
    	function wiew_media_upload&#40;&#41; &#123;
    		global $errdescr;
    
    		/* Check variables */
    		if &#40;strlen&#40;$_POST&#91;'title'&#93;&#41; == 0&#41; &#123;
    			$errdescr = "You haven't specified the media title.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		if &#40;strlen&#40;$_FILES&#91;'lv_source'&#93;&#91;'tmp_name'&#93;&#41; == 0&#41; &#123;
    			$errdescr = "You haven't specified the left video source.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		if &#40;strlen&#40;$_FILES&#91;'rv_source'&#93;&#91;'tmp_name'&#93;&#41; == 0&#41; &#123;
    			$errdescr = "You haven't specified the right video source.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		
    		if &#40;!is_uploaded_file&#40;$_FILES&#91;'lv_source'&#93;&#91;'tmp_name'&#93;&#41;&#41; &#123;
    			$errdescr = "Failed to upload files &#40;left video&#41;.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		if &#40;!is_uploaded_file&#40;$_FILES&#91;'rv_source'&#93;&#91;'tmp_name'&#93;&#41;&#41; &#123;
    			$errdescr = "Failed to upload files &#40;right video&#41;.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		if &#40;&#40;strlen&#40;$_FILES&#91;'a_source'&#93;&#91;'tmp_name'&#93;&#41; > 0&#41; && !is_uploaded_file&#40;$_FILES&#91;'a_source'&#93;&#91;'tmp_name'&#93;&#41;&#41; &#123;
    			$errdescr = "Failed to upload files &#40;audio&#41;.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    
    		/* Check whether destination directory exists */
    		$mediadir = trim&#40;$GLOBALS&#91;'media_prefix'&#93;.$_POST&#91;'title'&#93;&#41;;
    		if &#40;is_dir&#40;$mediadir&#41;&#41; &#123;
    			$errdescr = "Media already uploaded.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    
    		/* Create media directory */
    		if &#40;!mkdir&#40;$mediadir&#41;&#41; &#123;
    			$errdescr = "Failed to create media directory.";
    			utils_show_error&#40;$errdescr&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    
    		/* Upload files */
    		print "<pre>";
    		/* Upload and move files to the correct position */
    		if &#40;!move_uploaded_file&#40;$_FILES&#91;'lv_source'&#93;&#91;'tmp_name'&#93;, $mediadir."/LVIDEO.mpg"&#41;&#41; &#123;
    			$errdescr = "Generic upload error.";
    			utils_show_error&#40;$errdescr&#41;;
    			
    			wiew_media_delete&#40;$_POST&#91;'title'&#93;&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		if &#40;!move_uploaded_file&#40;$_FILES&#91;'rv_source'&#93;&#91;'tmp_name'&#93;, $mediadir."/RVIDEO.mpg"&#41;&#41; &#123;
    			$errdescr = "Generic upload error.";
    			utils_show_error&#40;$errdescr&#41;;
    			
    			wiew_media_delete&#40;$_POST&#91;'title'&#93;&#41;;
    			return &#40;FALSE&#41;;
    		&#125;
    		if &#40;strlen&#40;$_FILES&#91;'a_source'&#93;&#91;'tmp_name'&#93;&#41; > 0&#41; &#123;
    			if &#40;!move_uploaded_file&#40;$_FILES&#91;'a_source'&#93;&#91;'tmp_name'&#93;, $mediadir."/AUDIO.wav"&#41;&#41; &#123;
    				$errdescr = "Generic upload error.";
    				utils_show_error&#40;$errdescr&#41;;
    				
    				wiew_media_delete&#40;$_POST&#91;'title'&#93;&#41;;
    				return &#40;FALSE&#41;;
    			&#125;
    		&#125;
    		print "</pre>";
    		
    		$errdescr = "";
    		
    		return &#40;TRUE&#41;;
    	&#125;
    Effectively the script works, but only on small files... I've checked it. I've edited on /etc/php/apache2/php.ini the following directives:

    file_uploads = on
    post_max_size = 2048M
    upload_max_filesize = 2048M
    max_execution_time = 360
    max_input_time = 360
    memory_limit = 1024M

    Now that's the problem... No POST variables are available to the PHP script. My needs are to upload 2/3 files, but because they are MPEG videos, they are very large (@300 MB for each video and @70M for audio).

    Thank you is advance... this is very urgent!
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

  2. #2
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401

    Solved!

    OK, I've worked on it 2/3 days, but now I've found the trick...

    post_max_size directive can't be of 2048... its upper limit is 2047!!!!

    Now everything works... I've checked also that script memory limit is not important, so I've set it on the default value...
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

Posting Permissions

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