0

Hi,

I'm having a very strange problem. I use lampp on centOS linux. My application has a upload Script (in PHP) which uploads file to file system. after upload and moving file to correct location, uploaded files are getting deleted. I check file upload and moving of file by putting all the status in a text log file. files are getting uploaded properly and after upload I'm able to move the files to it's correct location.

thanks,
Jitender Aryan

Attachments error_in_upload.JPG 100.99 KB
2
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by FlashCreations
0

I believe you problem is you are looking in the wrong spot. It looks to me like the file in your screenshot was uploaded to /web/htdocs/m/s/41/f/793/f41-793.ogg, but I can't tell. Could we see some code so that we can determine where the files are going. Also, I would add an index to pnp.bojam.com/php because any client can view the file listing for that directory. EDIT: For now though, if you don't mind: please don't create an index so that I can take a look at your file structure. You can add an index after you problem is solved!

0

Please see the attached file for the code I used to upload files.

Attachments
Below is the code which I used to upload file and call other scripts:


<?php
session_start ();
error_reporting ( E_ALL & ~ E_NOTICE );
ini_set ( 'display_errors', 1 );
require_once 'config.php';
require_once 'models/general.php';
require_once 'models/validations.php';
require_once 'models/BatchPut.php';
if (file_exists("fileUploadLog-".date('Y-m-d',strtotime('-1 day')).".txt")){
copy("fileUploadLog-".date('Y-m-d',strtotime('-1 day')).".txt", $_SERVER['DOCUMENT_ROOT']."/fileUploadLogs/fileUploadLog-".date('Y-m-d',strtotime('-1 day')).".txt");
if(file_exists( $_SERVER['DOCUMENT_ROOT']."/fileUploadLogs/fileUploadLog-".date('Y-m-d',strtotime('-1 day')).".txt")){
@unlink( "fileUploadLog-".date('Y-m-d',strtotime('-1 day')).".txt");
}
} 

$fp = fopen ( "fileUploadLog-".date('Y-m-d').".txt", "a+" );
fwrite($fp,"\t \n \n Start Time: ".date('Y-m-d H:i:s'));



if ($_POST) {
	if (! empty ( $_POST ['fileId'] ) || !empty ($_POST ['trackId'] )) {
		if (! empty ( $_POST ['songId'] )) {
		
			$songId = $_POST ['songId'];
			if (! empty ( $_POST ['fileId'] ) ){
			$fileId = $_POST ['fileId'];
			} else {
			$fileId = $_POST ['trackId'];
			fwrite($fp,"[$fileId] \n");
			fwrite($fp,"\t [$fileId]IP: ".$_SERVER['REMOTE_ADDR']." \n");
			if (( string ) $_POST ['ownerId'] !== "") {
				$ownerId = $_POST ['ownerId'];
			} else {
				fwrite ( $fp, "\t [$fileId]Error:no ownerID \n" );
				fwrite($fp,"\t [$fileId]End Time: ".date('Y-m-d H:i:s')." \n \n \n");
				die ( 'OwnerId not Provided' );
			}
			
		}
			fwrite ( $fp, "\t [$fileId]songId:" . $songId." \n" );
			fwrite ( $fp, "\t [$fileId]fileId:" . $fileId." \n" );
			
			if (! empty ( $_FILES )) {
				// create folders
				fwrite ( $fp, "\t [$fileId]File Details: \n" );
				
				$extn = substr ( $_FILES ['uploadfile'] ['name'], strrpos($_FILES ['uploadfile']['name'],".")+1 );
				$extn = strtolower ( $extn );
				fwrite ( $fp, "\t \t [$fileId]File Size: " .  $_FILES ['uploadfile'] ['size']." \n" );
				fwrite ( $fp, "\t \t [$fileId]File Name: " .  $_FILES ['uploadfile'] ['name']." \n" );
				fwrite ( $fp, "\t \t [$fileId]File Extension: " .  $extn." \n" );
				fwrite ( $fp, "\t \t [$fileId]File Temp Name: " .  $_FILES ['uploadfile'] ['tmp_name']." \n \n" );
				$path = MUSIC_PATH . "s/" . $songId . '/f/' . $fileId . "/";
				$name = "f" . $songId . "-" . $fileId;
				fwrite($fp, "\t [$fileId]File Saving Path: ".$path." \n");
				fwrite($fp, "\t [$fileId]New File Name: ".$name." \n");
				//var_dump($_FILES);//['uploadFile']['name'];
				mkdir ( $path, 0777, true );
				$general = new general ( );
				
				$general->uploadFile ( 'uploadfile', $name . "." . $extn, $path );
				
				fwrite ( $fp, "\t [$fileId]Message from file Upload: " . $general->message." - ".date('Y-m-d H:i:s')." \n" );
				echo $general->message;
				if (file_exists ( $path . "/" . $name . "." . $extn )) {
					
					//update owners stats
					$URL = DB_SCRIPT_PATH . "ownerUpdate.php?ownerId=" . $ownerId;
					fwrite($fp,"\t [$fileId]URL for upading Owner Stats: ".$URL." - ".date('Y-m-d H:i:s')." \n");
					$cURLHandler = curl_init ();
					curl_setopt ( $cURLHandler, CURLOPT_URL, $URL );
					curl_exec ( $cURLHandler );
					fwrite($fp,"\t [$fileId] Result From Owner Stat Update Script : ".$result." - ".date('Y-m-d H:i:s')." \n");
					
					$URL = DB_SCRIPT_PATH . "datafile.php?action=update&uploadStatus=0filePath=m/s/".$songId."/f/".$fileId."/".$name."&fileType=" . $_FILES ['uploadfile'] ['type'] . "&fileExtension=" . $extn."&fileId=".$fileId;
					fwrite($fp,"\t [$fileId]URL for upading file Stats: ".$URL." \n");
					$cURLHandler = curl_init ();
					curl_setopt ( $cURLHandler, CURLOPT_URL, $URL );
					curl_exec ( $cURLHandler );
					fwrite($fp,"\t [$fileId]Result From File Stat Update Script : ".$result." - ".date('Y-m-d H:i:s')." \n");
					
					//request for jox to create files
					$URL =SERVER_PHP_PATH." ".MIXER_SCRIPT_PATH . "joxCommandCLI.php " . $songId . " " . $fileId . " " . $extn;
					fwrite($fp,"\t [$fileId]URL for Jox Request: ".$URL." - ".date('Y-m-d H:i:s')." \n");
					exec($URL);
					fwrite($fp,"\t [$fileId]End Time: ".date('Y-m-d H:i:s')." \n \n \n");				
					
				
				} else {
					fwrite ( $fp, "\t [$fileId]Error: File Doesn't exist in filesystem  \n" );
					fwrite($fp,"\t [$fileId] End Time: ".date('Y-m-d H:i:s')." \n \n \n");
					die ( "WAV File don't Exist- in files" );
				}
			
			} else {
				echo "No File Data recieved";
				fwrite ( $fp, "\t Error: No File Data \n" );
				fwrite($fp,"\t End Time: ".date('Y-m-d H:i:s')." \n \n \n");
				die ();
			}
		
		} else {
			echo "songId is Null";
			fwrite ( $fp, "\t Error: No Song \n" );
			fwrite($fp,"\t End Time: ".date('Y-m-d H:i:s')." \n \n \n");
			die ();
		}
	} else {
		echo "fileId is Null";
		fwrite ( $fp, "\t Error: No File ID\n" );
		fwrite($fp,"\t End Time: ".date('Y-m-d H:i:s')." \n \n \n");
		die ();
	}
} else {
	echo "No proper upload request.";
	fwrite ( $fp, "\t Error: Not Proper request. Post Fields are empty \n" );
	fwrite($fp,"\t End Time: ".date('Y-m-d H:i:s')." \n \n \n");
	die ();
}
?>
0

It doesn't appear that you accidentally delete the song file in that code, nor do I spot any problems. I believe we need to see where you define your class "general" (Taking a good guess I would say that's in models/general.php).

0

I have attached code block (general class) which uploads the file and also the code block of validations class which checks and validates the uploaded file.

I would like to tell you that we have 3 servers on two servers same code is working fine but not on the third one.

thanks,
Jitender Aryan

Attachments
function uploadFile($fld,$name,$path){
	$file=new validations();
	//var_dump($_FILES[$fld]);
		switch($_FILES[$fld]['error']){
			case 0:
				if($file->validateFile($fld)){//if valid file
					if(move_uploaded_file($_FILES[$fld]['tmp_name'],$path."/".$name))
					$this->message="Track Uploaded!!!";
				} else { //if not valid file
					$this->message="Uploaded file in not Valid!!!".$file->result;
				}
				break;
			case 1:
				$this->message="Upload File exceeded Maximum file size allowed by the server.";
				break;
			case 2:
				$this->message="Upload File exceeded Maximum file size allowed.";
				break;
			case 3:
				$this->message="Uploaded file was only partially uploaded.";
				break;
			case 4:
				$this->message="No File Uploaded.";
				break;
			case 6:
				$this->message="Temporary file folder missing.";
				break;
			case 7:
				$this->message="Failed to write file to disk.";
				break;
			case 8:
				$this->message="File upload stopped due to extension.";
				break;
			}
		return $this->message;
	
	
	}ield;
		return false;
		}
	
	}
function validateFile($fileField){
		if($_FILES[$fileField]['name']!=""){	
			if($_FILES[$fileField]['size']>0){  //check if file size if larger then zero
				if(is_uploaded_file($_FILES[$fileField]['tmp_name'])){//check if file is uploaded and not provided by any other source
				return true;				
				} else { //if File is provided by Any other Source
				$this->result="Provided file in not uploaded using our system. Stopping process to stop any attack to the Script.";
				return false;
				}
			} else { //if file size is 0 or empty file
				$this->result="Empty File Uploaded.";
				return false;
			} // END if empty file
	
		}else { //if file Field is Empty
		$this->result="File Field is Empty. Please select any File to upload.".$this->fileField;
		return false;
		}
	
	}
ield;
		return false;
		}
	
	}
0

Well there is a problem with the general file. It seems like you have too many brackets. See below:

function uploadFile($fld,$name,$path){
	$file=new validations();
	//var_dump($_FILES[$fld]);
	switch($_FILES[$fld]['error']){
		case 0:
			if($file->validateFile($fld)){//if valid file
					if(move_uploaded_file($_FILES[$fld]['tmp_name'],$path."/".$name)) $this->message="Track Uploaded!!!";
			} else { //if not valid file
				$this->message="Uploaded file in not Valid!!!".$file->result;
			}
			break;
		case 1:
			$this->message="Upload File exceeded Maximum file size allowed by the server.";
			break;
		case 2:
			$this->message="Upload File exceeded Maximum file size allowed.";
			break;
		case 3:
			$this->message="Uploaded file was only partially uploaded.";
			break;
		case 4:
			$this->message="No File Uploaded.";
			break;
		case 6:
			$this->message="Temporary file folder missing.";
			break;
		case 7:
			$this->message="Failed to write file to disk.";
			break;
		case 8:
			$this->message="File upload stopped due to extension.";
			break;
	}
	return $this->message;	

//Whats all this down here!!
	}ield; //Whats ield;
		return false;
		}	
	}

What's with the stuff at the end? Also, it would be helpful to see the move_uploaded_file() function...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.