我目前正在编写一个脚本,用户在表单中输入一个数字,然后脚本在文件夹中搜索与该编号匹配的图像,并将其显示给用户(下载按钮即将到来)。现在我的代码看起来像这样:
text-align: center
现在,只有当用户输入目录中最后一个图像的编号时,此代码才有效。我想我得到了错误的基本原则。 $ images继续为$ dir分配数组中最后一项的值。至少我认为。问题是我可能是错的,而且我也不知道如何解决它。如果用户输入匹配目录中的任何照片然后中断,我希望if语句显示图像。任何帮助,将不胜感激。谢谢你们!
答案 0 :(得分:0)
您的foreach ($images as $value); {
错了:
foreach ($images as $value) {
应该是
foreach
(注意缺少的分号)
话虽如此,对于您的特定情况,扫描目录上的intval
可能不是最佳解决方案。尝试更好地验证输入(例如,如果ID始终是数字,请使用import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class RubberLinesPanel extends JPanel {
private Point current = null, point2 = null;
private double length;
private DecimalFormat fmt;
public RubberLinesPanel() {
LineListener listener = new LineListener();
addMouseListener(listener);
addMouseMotionListener(listener);
setBackground(Color.black);
setPreferredSize(new Dimension(400, 200));
fmt = new DecimalFormat("0.##");
}
public void paintComponent(Graphics page) {
super.paintComponent(page);
page.setColor(Color.yellow);
if (current != null && point2 != null)
page.drawLine(current.x, current.y, point2.x, point2.y);
page.drawString("Distance: " + fmt.format(length), 10, 15);
}
private class LineListener implements MouseListener, MouseMotionListener {
public void mousePressed(MouseEvent event) {
current = event.getPoint();
}
//--------------------------------------------------------------
// Gets the current position of the mouse as it is dragged and
// redraws the line to create the rubberband effect.
//--------------------------------------------------------------
public void mouseDragged(MouseEvent event) {
point2 = event.getPoint();
length = Math.sqrt(Math.pow((current.x - point2.x), 2) +
Math.pow((current.y - point2.y), 2));
repaint();
}
//--------------------------------------------------------------
// Provide empty definitions for unused event methods.
//--------------------------------------------------------------
public void mouseClicked(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
public void mouseMoved(MouseEvent event) {}
}
}
)并查看文件是否存在。