简体   繁体   English

为什么我不能从本地主机访问映像? 甚至可以通过Web服务显示图像吗?

[英]Why can't i access an image from the localhost? Is it even possible to display an image through web services?

Every time i try to display the image it's like the link is not correct. 每当我尝试显示图像时,就好像链接不正确。 Using the console i get the error 使用控制台我得到了错误

Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为404(未找到)

How can it not find it if it is in the same folder? 如果它在同一文件夹中,怎么找不到呢? I checked the link and i found that the correct link is xampp/htdocs/WebService/Client/images/1.jpg instead of localhost/WebService/Client/images/1.jpg but xampp/htdocs is treated as localhost itself, right? 我检查了链接,发现正确的链接是xampp / htdocs / WebService / Client / images / 1.jpg而不是localhost / WebService / Client / images / 1.jpg,但是xampp / htdocs被视为localhost本身,对吗? So what can be the solution for this? 那么对此有什么解决方案? I've been searching for 2 days. 我已经搜寻了2天。 By doing some research I even tried to create separate virtual hosts but to no avail. 通过做一些研究,我什至试图创建单独的虚拟主机,但无济于事。 It just can't locate file images from the localhost. 它只是无法从本地主机找到文件映像。 What can i do? 我能做什么? Please help. 请帮忙。

The codes for the client.php: client.php的代码:

<?php

if(isset($_POST['search_input']))
{
try
{
    $input = $_POST['search_input'];

    $wsdl = "http://localhost/WebService/UDDI/90210Store.wsdl";

    $options = array('cache_wsdl'=>WSDL_CACHE_NONE, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS);

    $client = new SoapClient($wsdl, $options);

    $response = $client->viewDressPerPrice($input);


    if(isset($response->DressPerPrice))
    {
        $HTMLDocument = "<!DOCTYPE html>
                         <html>
                         <head><h3>Dresses</h3></head>
                         <body>
                         <table border='1'>";

                         foreach($response->DressPerPrice as $record)
                         {
                             $HTMLDocument .= "<tr><td>".$record->Name."</td>";
                             $HTMLDocument .="<td>".$record->Price."</td>";
                             $HTMLDocument .="<td><img src=images/".$record->Image."/></td>";
                         }

                         $HTMLDocument .= "</table>
                                           </body>
                                           </html>";
       echo "<table border='1'><tr><td><img src='C:/xampp/htdocs/WebService/Client/images/1.jpg'/></td></tr></table>";
       echo $HTMLDocument;
    }


    else
    {
        echo "This field is not found in database";
    }
}

catch(Exception $e)
{
echo 'Exception: '.$e->getMessage();
}

catch(SOAPFault $exception)
{
echo 'SOAP Exception: '.$exception->getMessage();
}

}

else
{
header("Location: http://localhost/WebService/Client/Category.html");
}

?>

The wsdl: wsdl:

<?xml version="1.0" encoding="UTF-8" ?>
<definitions targetNamespace="http://www.shehzad.edu/webservice" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:this="http://www.shehzad.edu/webservice" xmlns="http://schemas.xmlsoap.org/wsdl/"
xsi:schemaLocation="http://schemas.xmlsoap.org/wsdl/ http://schemas.xmlsoap.org/wsdl/wsdl.xsd http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd">

<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.shehzad.edu/webservice"  elementFormDefault="qualified">
<xs:element name="Input" type="xs:string"/>
<xs:complexType name="DressType">
     <xs:sequence>
         <xs:element name="Name" type="xs:string"/>
         <xs:element name="Price" type="xs:integer"/>
         <xs:element name="Image" type="xs:anyURI"/>
     </xs:sequence>
</xs:complexType>

<xs:complexType name="ArrayOfDresses">
     <xs:sequence>
         <xs:element name="DressPerPrice" minOccurs="1" maxOccurs="unbounded" type="this:DressType"/>
     </xs:sequence>
</xs:complexType>
<xs:element name="Result" type="this:ArrayOfDresses"/>
</xs:schema>
</types>

<!--input message-->
<message name="getDressPerPriceRequest">
     <part name="input" element="this:Input"/>
</message>

<!--output message-->
<message name="getDressPerPriceResponse">
     <part name="result" element="this:Result"/>
</message>

<portType name="DressPerPricePortType">
     <operation name="viewDressPerPrice">
         <input message="this:getDressPerPriceRequest"/>
         <output message="this:getDressPerPriceResponse"/>
     </operation>
</portType>

<binding name="DressPerPriceBinding" type="this:DressPerPricePortType">
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
     <operation name="viewDressPerPrice">
         <soap:operation soapAction="http://www.shehzad.edu/webservice"/>
         <input><soap:body use="literal"/></input>
         <output><soap:body use="literal"/></output>
     </operation>
</binding>

<service name="DressPerPriceService">
     <port name="DressPerPricePort" binding="this:DressPerPriceBinding">
         <soap:address location="http://localhost/WebService/Server/Server.php"/>
     </port>
</service>
</definitions>

The image is being linked to through C:/xampp/htdocs/WebService/Client/images/1.jpg . 该图像通过C:/xampp/htdocs/WebService/Client/images/1.jpg链接到。 You have to link the image from localhost. 您必须从本地主机链接图像。 Websites (even local ones) don't have access to your C: drive. 网站(甚至本地网站)都无法访问您的C:驱动器。 So change the image to http://localhost/WebService/Client/images/1.jpg or even /WebService/Client/images/1.jpg will work. 因此,将图像更改为http://localhost/WebService/Client/images/1.jpg甚至可以使用/WebService/Client/images/1.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM