[GIS] Uploading shapefile to GeoServer

geoserverlayersPHPshapefile

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.

Update

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/dat‌astores/trash/file.s‌​hp"); 
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); ?>

Best Answer

A shapefile (despite it's name) consists of between 3 and 9 files sharing a common prefix but with different suffixes. You need to zip up all of the files to get a successful upload.

Related Question