Note that there are some explanatory texts on larger screens.

plurals
  1. POCan not connect to FTP when php on remote server, but connects when php is on localhost
    primarykey
    data
    text
    <p>I am pretty new to php, just learning how to upload to server via ftp.</p> <p>I have a file for connecting to ftp, it displays no error when it is on my localhost, but when i upload the file onto the remote server, it gave me an error straight away that it can't connect to server(would it be because they are the same server?) . At the moment it is displaying, <code>Cannot connect to host</code> And this is my first time doing FTP in php, so i hope my mistakes aren't too stupid. </p> <p>P.S. This is just for testing, so i will figure out the SQL injection issue later on with sqli_real_escape string.</p> <p>As i am also trying to do a form that upload images onto the remote server via ftp_put. But it is not working at the moment. But giving me an error <code>Warning: ftp_put() expects parameter 1 to be resource, boolean given in</code> Please give me some direction to why my errors are occurring. Thanks for your time, thanks!</p> <p>Agentftpconnect.php</p> <pre><code>&lt;?php $ftp_user_name='name'; $ftp_user_pass='pass'; $connection = 'testing.info'; $ftpconn_id = ftp_connect($connection) or die ("Cannot connect to host"); $login = ftp_login($ftpconn_id, $ftp_user_name, $ftp_user_pass); if (!$ftpconn_id) {die ("FTP connection has encountered an error!");} if (!$login) {die ("But failed at login Attempted to connect to $connection for user $ftp_user_name....");} ?&gt; </code></pre> <p>Submitform.php</p> <pre><code>&lt;?php ini_set('display_errors', 1); error_reporting(E_ALL); ob_start(); session_start(); include 'connect.php'; include 'Agentftpconnect.php'; if ($_POST) { //get form data $Listingname = addslashes(strip_tags($_POST['Listingname'])); $Location = addslashes(strip_tags($_POST['Location'])); $nobed = addslashes(strip_tags($_POST['nobed'])); $zip = addslashes(strip_tags($_POST['zip'])); $price = ($_POST['price']); if (!$Listingname||!$nobed||!$Location||!$zip||!$price) die ("Please fill out all fields"); else for($i=0;$i&lt;3;$i++) { if ((($_FILES["file"]["type"][$i] !== "image/gif") || ($_FILES["file"]["type"][$i] !== "image/jpeg") || ($_FILES["file"]["type"][$i] !== "image/jpg") || ($_FILES["file"]["type"][$i] !== "image/pjpeg") || ($_FILES["file"]["type"][$i] !== "image/x-png") || ($_FILES["file"]["type"][$i] !== "image/png")) &amp;&amp; ($_FILES["file"]["size"][$i] &gt; 400000)) die("File is not correct"); else{ if ($_FILES["file"]["error"][$i] &gt; 0) { echo "Return Code: " . $_FILES["file"]["error"][$i] . "&lt;br&gt;"; } else { echo "Upload: " . $_FILES["file"]["name"][$i] . "&lt;br&gt;"; echo "Size: " . ($_FILES["file"]["size"][$i] / 1024) . " kB&lt;br&gt;"; echo "Temp file: " . $_FILES["file"]["tmp_name"][$i] . "&lt;br&gt;"; echo "&lt;br&gt;"; if (file_exists("rentaid.info/rent" . $_FILES["file"]["name"][$i])) { die($_FILES["file"]["name"][$i] . " already exists please add another file, or change the name "); } else { $photo=$_FILES["file"]["name"][$i]; ftp_put($login,"rentaid.info/rent/$photo",$_FILES["file"]["tmp_name"][$i],FTP_ASCII); echo "Stored in: " . "rentaid.info/rent/" . $_FILES["file"]["name"][$i]; } } } } { $photo0=$_FILES["file"]["name"][0]; $photo1=$_FILES["file"]["name"][1]; $photo2=$_FILES["file"]["name"][2]; $username=$_SESSION['username']; //register into database mysqli_query($con,"INSERT INTO Listing (username,Listingname,Location,nobed,zip,price,pic1,pic2,pic3) VALUES ('$username','$Listingname','$Location','$nobed','$zip','$price','$photo0','$photo1','$photo2');") or die(mysqli_error()); echo "Listing Added"; } } else { ?&gt; &lt;form action="Submitlisting8.php" method="post" enctype="multipart/form-data"&gt; Listing Name:&lt;br /&gt; &lt;input type='text' name='Listingname'&gt;&lt;p /&gt; Location:&lt;br /&gt; &lt;input type='text' name='Location'&gt;&lt;p /&gt; Number of Beds:&lt;br /&gt; &lt;input type='test' name='nobed'&gt;&lt;p /&gt; Zip:&lt;br /&gt; &lt;input type='text' name='zip'&gt;&lt;p /&gt; Price:&lt;br /&gt; &lt;input type='text' name='price'&gt;&lt;p /&gt; &lt;label for="file"&gt;Pic1(File must be exceed 4mb):&lt;/label&gt; &lt;input type="file" name="file[]" id="file[]"&gt;&lt;br&gt; &lt;label for="file"&gt;Pic2(File must be exceed 4mb):&lt;/label&gt; &lt;input type="file" name="file[]" id="file[]"&gt;&lt;br&gt; &lt;label for="file"&gt;Pic3(File must be exceed 4mb):&lt;/label&gt; &lt;input type="file" name="file[]" id="file[]"&gt;&lt;br&gt; &lt;br&gt; &lt;input type='submit' name='submit' value='Submit'&gt; &lt;/form&gt; &lt;FORM METHOD="LINK" ACTION="agentaccount.php"&gt; &lt;INPUT TYPE="submit" VALUE="Back to Account"&gt; &lt;/form&gt; &lt;?php } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload