Jump to content

help with capture file upload


acctman

Recommended Posts

I need assistance with a few things with my coding.

1. where I grab the filename content...$filename = file_get_contents($_FILES['uploadedfile']['name']); will that work since I already moved the file to the /temp/files/? if not how would i say look in that folder?

 

2. two upload happen with my script one is for the .csv file and the other are the docx files. what I need help with is to capture the filenames from the flash part so i can upload them to /temp/files

 

3. as you can see i'm trying to use this as a php_self so how would i go about removing the upload.php in the upload_url for the flash? do I just put the name of the page or php_self code?

 

<?php
if(isset($_POST['submit'])) {

	// check .csv file has been uploaded... and on the server proceed   	
   	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], '../temp/files/')) {
     $filename = file_get_contents($_FILES['uploadedfile']['name']);
     
//*** process flash upload save files to /temp/files/ should go here

     $handle = fopen("$filename", "r");
     while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
    		if(file_exists('/temp/files/'. $data[0] .'.docx')) {
					$import="INSERT into kmmb_member1(docx_id,no_ahli,no_pin,nama,no_ic_baru,no_ic_lama) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
	       	mysql_query($import) or die(mysql_error());

//***  after insert move file
	   			rename('/temp/files/'. $data[0] .'.docx', '/docx_files/'. $data[0] .'.docx');

		 		}  
     }
     fclose($handle);
     print "Import done";
  
  	} else {
    	 echo "There was an error uploading the *.csv file, please try again!";
	}   
	     
} else {
   	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link href="swf_up/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="swf_up/swfupload/swfupload.js"></script>
<script type="text/javascript" src="swf_up/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="swf_up/js/fileprogress.js"></script>
<script type="text/javascript" src="swf_up/js/handlers.js"></script>
<script type="text/javascript">
var swfu;

SWFUpload.onload = function () {
var settings = {
	flash_url : "swf_up/swfupload/swfupload.swf",
	flash9_url : "swf_up/swfupload/swfupload_fp9.swf",
	upload_url: "swf_up/upload.php",
	post_params: {
		"PHPSESSID" : "NONE",
		"HELLO-WORLD" : "Here I Am",
		".what" : "OKAY"
	},
	file_size_limit : "100 MB",
	file_types : "*.*",
	file_types_description : "All Files",
	file_upload_limit : 100,
	file_queue_limit : 0,
	custom_settings : {
		progressTarget : "fsUploadProgress",
		cancelButtonId : "btnCancel"
	},
	debug: false,

	// Button Settings
	button_image_url : "swf_up/XPButtonUploadText_61x22.png",
	button_placeholder_id : "spanButtonPlaceholder",
	button_width: 61,
	button_height: 22,

	// The event handler functions are defined in handlers.js
	swfupload_preload_handler : swfUploadPreLoad,
	swfupload_load_failed_handler : swfUploadLoadFailed,
	swfupload_loaded_handler : swfUploadLoaded,
	file_queued_handler : fileQueued,
	file_queue_error_handler : fileQueueError,
	file_dialog_complete_handler : fileDialogComplete,
	upload_start_handler : uploadStart,
	upload_progress_handler : uploadProgress,
	upload_error_handler : uploadError,
	upload_success_handler : uploadSuccess,
	upload_complete_handler : uploadComplete,
	queue_complete_handler : queueComplete	// Queue plugin event

};

swfu = new SWFUpload(settings);
}

</script>
</head>
<body>


<div id="content">

<h2>Upload</h2>
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
	<div id="divSWFUploadUI" style="margin-top: 20px;">
		<span>Select .csv file: 
			<input name='uploadedfile' type='file' /><br />
		</span>
		<div class="fieldset  flash" id="fsUploadProgress">
		<span class="legend">Upload Queue</span>
		</div>
		<p id="divStatus">0 Files Uploaded</p>
		<p>
			<span id="spanButtonPlaceholder"></span>
			<input id="btnCancel" type="button" value="Cancel All Uploads" disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;" />
			<br />
		</p>
	</div>
<!-- -->

</form>
</div>
</body>
</html>


<?php
   }
?>

Link to comment
Share on other sites

You're using it incorrectly, the destination should also include $_FILES['uploadedfile']['name'] after the folder. See the example on the manual. Once the file has been uploaded using file_get_contents() should be fine, just point it to the destination address you specify in move_uploaded_file().

 

For your 3rd query I'd recommend putting this upload code in a separate file, otherwise yes you could just echo the PHP_SELF server variable.

Link to comment
Share on other sites

You're using it incorrectly, the destination should also include $_FILES['uploadedfile']['name'] after the folder. See the example on the manual. Once the file has been uploaded using file_get_contents() should be fine, just point it to the destination address you specify in move_uploaded_file().

 

For your 3rd query I'd recommend putting this upload code in a separate file, otherwise yes you could just echo the PHP_SELF server variable.

 

I send you a pvt msg...

Link to comment
Share on other sites

You're using it incorrectly, the destination should also include $_FILES['uploadedfile']['name'] after the folder. See the example on the manual. Once the file has been uploaded using file_get_contents() should be fine, just point it to the destination address you specify in move_uploaded_file().

 

For your 3rd query I'd recommend putting this upload code in a separate file, otherwise yes you could just echo the PHP_SELF server variable.

 

does this look right?

 

if(isset($_POST['submit'])) {
	// check .csv file has been uploaded... and on the server proceed 

$uploaddir = '../temp/files/';
$uploadcsv = $uploaddir . basename($_FILES['userfile']['name']);
	  	
   	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadcsv)) {
     $filename = file_get_contents($uploadcsv);
     $batchid = $_POST['batchid'];
     $handle = fopen("$filename", "r");
     while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
    		if(file_exists('/temp/files/'. $data[0] .'.docx')) {
	   			rename('/temp/files/'. $data[0] .'.docx', '/docx_files/'. $data[0] .'.docx');
					$import="INSERT into kmmb_member1(docx_id,no_ahli,no_pin,nama,no_ic_baru,no_ic_lama,batch) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$batchid')";
	       	mysql_query($import) or die(mysql_error());
		 		}  
     }
     fclose($handle);
     print "Import done";
  
  	} else {
    	 echo "There was an error uploading the *.csv file, please try again!";
	}   
	     
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.