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