Jump to content

uploading a file


An7hony

Recommended Posts

Here is some of my form:

 

<form method="POST" enctype="multipart/form-data" action="" onsubmit="return false;" id="myid">


<label for="txtmessage" class="labsmall">Upload<span>*</span></label> <input type="hidden" name="MAX_FILE_SIZE" value="20000000000"><input name="userfile" type="file" class="browse" id="userfile"><br />

<input type="image" src="images/applybut.gif" class="applybutton" onclick="ajax_form('myid','validate.php','receiver');"  />

 

Here is some of my validate.php:

<?

//file upload
$uploadDir = '/blabla/';	
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

    // get the file extension first
$ext      = substr(strrchr($fileName, "."), 1); 

// generate the random file name


// and now we have the unique file name for the upload file
    $filePath = $uploadDir . $fileName;

    // move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
    $result    = move_uploaded_file($tmpName, $filePath);
if (!$result) {
	echo 'Error uploading the <strong>file</strong>';

}

$SQL = " INSERT INTO table ";
$SQL = $SQL . " (name, size, type, path) VALUES ";
$SQL = $SQL . " ('$fileName', '$fileSize', '$fileType', '$filePath') ";
$result = mysql_db_query($db,"$SQL",$cid);
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

mysql_close($cid);
?>

 

Will this work using: onclick="ajax_form('myid','validate.php','receiver');"

 

The rest of my data gets posted except the file upload

 

Thanks for the help guys

Link to comment
https://forums.phpfreaks.com/topic/202965-uploading-a-file/
Share on other sites

To create a "ajax style" upload, your need to put the file input into an iframe or something then use JS to do a submit post, or something like that, its all down to security.

Options options would be to use another client side language, ie java, flash etc

or just have the upload on another page  :shrug:

 

hope that helps

Link to comment
https://forums.phpfreaks.com/topic/202965-uploading-a-file/#findComment-1063608
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.