redpedia Posted May 18, 2008 Share Posted May 18, 2008 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:password@ftp.domain.com/’.$_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 ? Quote Link to comment Share on other sites More sharing options...
phorman Posted May 18, 2008 Share Posted May 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
redpedia Posted May 18, 2008 Author Share Posted May 18, 2008 thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.