Jump to content

fileupload


conan318

Recommended Posts

 

I am writing a file upload form the file uploads works fine. however i also need to a jobnumber which is in a hidden field which i cant seem to send the value along with it any help would be great thanks.

 

form.php

<script language="javascript" type="text/javascript">
function init() {
document.getElementById('uploadedfile').onsubmit=function() {


	document.getElementById('uploadedfile').target = 'upload_target'; //'upload_target' is the name of the iframe
	document.getElementById('jobnumber').value.target = 'upload_target';

}

}
window.onload=init;


</script>


<form id="uploadedfile" method="post" enctype="multipart/form-data" action="upload.php">
  <input type="hidden" name='jobnumber' value="<?php echo uniqid() ?>" />
<input name="uploadedfile" id="uploadedfile" size="27" type="file" /><br />
<input type="submit" name="action" value="Upload" /><br />
<iframe id="upload_target" name="upload_target" src="" ></iframe>
</form>

 

 

upload.php

$id=$_POST['jobnumber'];


if ($_FILES['uploadedfile']['size']!= 0)





$ext_a = explode(".", $_FILES['uploadedfile']['name']);

$ext = $ext_a[1];
if ( ($ext!=="zip" && $ext!=="ZIP" && $ext!=="zip" && $ext!=="ZIP" )){
echo "Error IMAGES MUST BE EITHER PNG, GIF OR JPG ";
echo "<a href='gal.php'>Go back</a>";
die;
}else{

/* hashes the file name with the date and time to genrate a uniue file name*/
$img=md5($_FILES['uploadedfile']['name'] . date("m.d.y H:m:s")) . "." . $ext;
$target_path = "../testup/";

$target_path = $target_path .basename($img); 




if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". $img;
echo"<br>";
echo $id;








}else{
echo "Sorry your password does not match"; 


}}
?>

Link to comment
https://forums.phpfreaks.com/topic/263092-fileupload/
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.