向代码添加标记的问题 [英] Problem With Adding Tag To The Code

查看:73
本文介绍了向代码添加标记的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户在文件的每一行上传一个带有十进制值的纯文本文件(例如36.81)。我必须上传它,打开它并制作直方图。我已经完成了所有工作,但是在我应该做的img标签的帮助下无法完成。这是我编写的代码:



用于上传文件并将所有值包含在数组中的代码

The user uploads a plain text file with a decimal value(eg. 36.81) on each line of the file. I have to upload this, open it and make a histogram out of it. I have done everything but cannot do it with the help of the img tag which I am supposed to do. Here is the code I have written as of yet:

Code for uploading the file and feeding all values in an array

<?php
if(($_FILES['img'] != '') && ($_FILES["img"]["type"] == "text/plain"))
		{
			move_uploaded_file($_FILES['img']['tmp_name'], "upload/" . $_FILES['img']['name']);
		}
		else
		{
			die ("There is an error in your upload. <br> Either the file is not a .txt file or you havent selected a file") ;
		}
		$data = array();
		$fp = @fopen ("upload/" . $_FILES['img']['name'], "r");
		if ($fp)
		{
			while(!feof($fp)) 
			{
				$this_line = fgets($fp);
				$this_line = chop($this_line);
				array_push($data,$this_line);
		}
		
		fclose($fp);
		}
echo("<img src='histogram.php?' alt='None' />");
?>





使用代码创建直方图$ data数组(histogram.php)





Code to create a histogram using the $data array(histogram.php)

<?php
$sum = array_sum($data);
$num = count($data);

header("Content-type: image/jpeg");

$height = 700;
      $width = 50*$num;

      $im = imagecreate($width,$height);

$white = imagecolorallocate($im,255,255,255);
      $black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,220,0,0);

      imageline($im, 10, 5, 10, 600, $black);
      imageline($im, 10, 600, 200*$num, 600, $black);

// Now plot each column
      $x = 15;
      $y = 600;
      $x_width = 20;
      $y_ht = 0;

      for ($i=0;$i<$num;$i++){

        $y_ht = $data[$i];

      imagefilledrectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
            imagestring( $im,2,$x-2,$y+10,$data[$i],$black);

        $x += ($x_width+30);
      }

      imagejpeg($im);
imagedestroy($im);
?>





目前,它有效,因为这两段代码都在一个php文件中。但我需要以这种方式使用它们并且它们不起作用,因为histogram.php无法读取数据数组。有人知道这样做的方法吗?



At present, it works because both the pieces of codes are in one php file. But I need to have them in this way and they don''t work because the data array cannot be read by histogram.php. Anyone knows a way to do that?

推荐答案

_FILES [' img']!= ' ')&& (
_FILES['img'] != '') && (


_FILES [ img] [ type] == text / plain))
{
move_uploaded_file(
_FILES["img"]["type"] == "text/plain")) { move_uploaded_file(


_FILES [ ' img'] [' tmp_name' ], upload /
_FILES['img']['tmp_name'], "upload/" .


这篇关于向代码添加标记的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆