I successfully created workspace in GeoServer using cURL in PHP following the GeoServer REST Guide. But I am having problems when trying to upload Shapefile. I followed the instructions on Uploading Shapefiles from GeoServer REST Guide but I can't seem to get it right. I keep getting Wrong Magic Number error. Also I want to upload shp file rather than zip.
I am a beginner in GIS.
Everything works fine when I use CURL
curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @trash.zip localhost:8080/geoserver/rest/workspaces/mySpace/datastores/…
but fails with the following PHP code:
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://localhost:9090/geoserver/rest/workspaces/mySpace/datastores/trash/file.shp"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $post = array( "file" => "@" .realpath("trash.zip") ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_USERPWD, "admin" . ":" . "geoserver"); $headers = array(); $headers = "Content-Type: application/zip"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); curl_close ($ch); ?>