Ciao a tutti, ho creato queste due semplici pagine per fare l'upload di un file dal mio HDD al mio spazio web usando CURL.
Questa è la prima volta che utilizzo CURL.
index.php
upload.phpcodice:<form action="index.php" method="post" enctype="multipart/form-data"> <input type="file" name="image"/> <input type="submit" value="Post"/> </form> <?php if(isset($_FILES['image']['tmp_name'])){ $ch = curl_init(); $cfile = new CURLFile($_FILES['image']['tmp_name'], $_FILES['image']['type'], $_FILES['image']['name']); $data = array("myimage"=>$cfile); curl_setopt($ch, CURLOPT_URL, 'http://www.miosito.net/listino/test2/upload.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURL_POSTFIELDS, $data); $response = curl_exec($ch); if($response == true){ echo 'File posted'; }else{ echo 'Error: ' . curl_errno($ch); } } ?>
codice:<?php if(isset($_FILES['image']['tmp_name'])){ $path = "uploads/" . $_FILES['image']['name']; move_uploaded_file($_FILES['image']['tmp_name'], $path); } ?>
Ricevo sempre errori sull'URL.
Ho provato a modificare l'URL come segue, ma niente da fare...
ed anche cosìcodice:curl_setopt($ch, CURLOPT_URL, "/home2/igxxxxxx/public_html/listino/test2/upload.php");
codice:curl_setopt($ch, CURLOPT_URL, "upload.php");
Qualcuno gentilmente potrebbe aiutarmi a capire dove sbaglio?
Sto perdendo veramente la testa.
Grazie.
P.S.
index.php e upload.php si trovano nella stessa cartella sul server.
La versione di php è superiore alla 5.5

Rispondi quotando