Jump to content

[SOLVED] How to store a path in mysql db for this ftp upload script ?


redpedia

Recommended Posts

I need a script to upload files through ftp and store their path inside mysql Database, now i've found a script use something called Tutorial: FTP Upload via cURL, here is the script , all i need is to get the path from this script and put it inside mysql insert syntax, but i don't know which var because iam still newbie in php , could you please help ?!

 

Here is the script

 

HTML FORM

<form action="curlupload.php" method="post" enctype="multipart/form-data">
<div>
<label for="upload">Select file</label>
<input name="upload" type="file" />
<input type="submit" name="Submit" value="Upload" />
</div>
</form>

 

PHP Action

<?php
if (isset($_POST[‘Submit’])) {

if (!empty($_FILES[‘upload’][‘name’])) {

  $ch = curl_init();

  $localfile = $_FILES[‘upload’][‘tmp_name’];

  $fp = fopen($localfile, ‘r’);

  curl_setopt($ch, CURLOPT_URL, ‘ftp://ftp_login:[email protected]/’.$_FILES[‘upload’][‘name’]);

  curl_setopt($ch, CURLOPT_UPLOAD, 1);

  curl_setopt($ch, CURLOPT_INFILE, $fp);

  curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));

  curl_exec ($ch);

  $error_no = curl_errno($ch);

  curl_close ($ch);

        if ($error_no == 0) {

          $error = ‘File uploaded succesfully.’;

        } else {

          $error = ‘File upload error.’;

        }

} else {

      $error = ‘Please select a file.’;

}

}

?>

 

could you please give the insert syntax for the file path ?

 

 

this is not the best script I have seen that will do the job, as you are doing any verifications, but to answer your question:

 

 

add the following after the line :  $fp = fopen($localfile, ‘r’);

$path = getCWD;   // returns the current directory you are in.
$fullpath = $path . $localfile;

 

then use $fullpath as the path to store in the database.

 

 

Also, you need to check out:  http://us2.php.net/manual/en/features.file-upload.php

This is by the book the way you need to process uploaded files.  You may even want to throw in a filesize check to see if they are exceeding some kind of quota.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.