0

Trying to pass a file path location into the data="" of an html .

Here's the code in php that I am pulling from:

$filedatetime = date ("m-d-o_His");

// Save XFDF array to file
$result_path = dirname(__FILE__) . "\\results";
$xfdf_filename = $filedatetime . '.xfdf';
$xfdf_file_path = $result_path . "\\" . $xfdf_filename;
//$toBePassed = "results\\" . $xfdf_filename;
$toBePassed = $xfdf_filename;

and here's the json_encode call:

<object type="application/vnd.adobe.xfdf" data=<?php echo json_encode($toBePassed) ?> width="300" height="200"></object>

The file that is being generated is in a results folder, so I am trying to literally add "results/" to the front of the php variable. You can see that I tried to do it, but since php requires two backslashes, when I pass it, it comes out: "results\\10-15-2013_112852.xfdf". I'm sure at which point I can add the string to the front of the variable name. Thanks


while x !="exit" or y !="exit":

will return true unless both x and y = 'exit'

The behavior you're describing would require

while x !="exit" and y !="exit":

in order to allow either x or y to end the while loop.

The other behavior you're asking for (breaking immediately after 'exit' is entered) would be easily accomplished by including the rest of the loop in an if clause to test for 'exit'

The rest of the erratic behavior you're describing (print statements) is like caused by indentation error.

Here's a version of what I think you're describing, using your original code that works in Python 3.3

x=0
y=0
while x !="exit" and y !="exit":
    x= input("Enter your name: ")
    if x != 'exit':
         y= input("Enter your grade: ")
         if y!= "exit":
              g=int(y)
              if g<50 or g>100:
                   print("Invalid input")
              else:
                   if g>=50 and g<70:
                        print("not a good grade,work harder")
                   elif g>=70 and g<90:
                        print("Nice grade, try to get higher next time")
                   else:
                        print("Excellent grade!")
print("Good bye")
4

3 回答 3

0

你试过了吗

data="<?php echo json_encode($xfdf_filename); ?>"

(注意 php 标签周围的引号 - 否则 HTML 将忽略无效的属性定义)

于 2013-10-15T22:32:49.807 回答
0
<object id="XFDFElement" type="application/vnd.adobe.xfdf" data="results/<?=json_encode($xfdf_filename)?>" width="300" height="200"></object>

更短更容易:)

于 2014-01-13T13:37:03.890 回答
0

我找到了解决方案。如果还有更好的方法请评论,谢谢!

<object id="XFDFElement" type="application/vnd.adobe.xfdf"></object>
<script type="text/javascript">
    var strPath = "results/" + <?php echo json_encode($xfdf_filename) ?>;
    document.getElementById("XFDFElement").data = strPath;
</script>
于 2013-10-15T22:13:29.123 回答