Skip to content

Instantly share code, notes, and snippets.

@nprussell
Created June 13, 2016 12:43
Show Gist options
  • Save nprussell/1209bb929d2eafd20c92c5302cff4cf9 to your computer and use it in GitHub Desktop.
Save nprussell/1209bb929d2eafd20c92c5302cff4cf9 to your computer and use it in GitHub Desktop.
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, the file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
} else{
echo "no post data";
}
$uploadedFile = "uploads/out.upz";
$handle = fopen($uploadedFile, 'rb');
if( ! $handle ) {
throw new Exception( "Can't open file" );
}
echo "<br><br>";
//echo $buffer = fread( $handle, 14 );
echo "<br><br>";
$str = '';
while (($read = fgetc($handle)) !== "\0") {
$str .= $read;
}
echo $str;
fclose( $handle );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment