Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6352697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:16:22+00:00 2026-05-24T22:16:22+00:00

Am using Shared server. I can save external images using curl. But am unable

  • 0

Am using Shared server.

I can save external images using curl. But am unable to save the path and file info to mysql.

<form method="post" enctype="multipart/form-data">
<table>
 <tr><td><b>URL: </b> </td><td><input type="**text**" name="url" id="url" size=40></td>  </tr>
 <tr><th colspan=2><p><input name="upload" type="submit" class="box" id="upload" value="Upload"></p></th></tr>
 </table>
 </form>

 <?php

 set_time_limit(0);
 ini_set('display_errors',true);//Just in case we get some errors, let us know....

 if (isset($_POST['upload']))
 {

  $url = $_POST['url'];
  $dir = "./files/";

  $fileName = $_FILES['url']['name'];
  $fileSize = $_FILES['url']['size'];
  $fileType = $_FILES['url']['type'];
  $filePath = $dir . $fileName;

  $ch = curl_init($url);
  $fp = fopen ($local_file, 'w+');
  $ch = curl_init($remote_file);
  curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  curl_setopt($ch, CURLOPT_FILE, $fp);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_ENCODING, "");
  curl_exec($ch);
  curl_close($ch);

  include ('db.php');
  if(!get_magic_quotes_gpc())
  {
  $fileName = addslashes($fileName);
  $filePath = addslashes($filePath);
  }
  $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
 mysql_query($query);
 mysql_close($conn);
 }

It is not working when I change input type to text from file.

I need to get file info and save to mysql server

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:16:23+00:00Added an answer on May 24, 2026 at 10:16 pm

    Have a go with this:

    <form method="post" enctype="application/x-www-form-urlencoded">
      <table>
        <tr>
          <td style="font-weight:bold;">URL:</td>
          <td><input type="text" name="url" id="url" size=40 value="http://" /></td>
        </tr>
        <tr>
          <!-- Why is this a <th> and not a <td> ? -->
          <th colspan="2"><input name="upload" type="submit" class="box" id="upload" value="Upload" /></th>
        </tr>
      </table>
    </form>
    
    <?php
    
      set_time_limit(0);
      ini_set('display_errors',true);//Just in case we get some errors, let us know....
    
      if (isset($_POST['upload'])) {
    
        // Build local file system paths
        $baseDir = "./files";
        $fileName = basename(rtrim($_POST['url'],'/')); // This means that if someone specifies the root of a domain (/) it will call the local file "domain"
        $filePath = rtrim($baseDir,'/')."/$fileName";
    
        // Try to parse the URL we have been given and add any missing required info
        if ((!$parts = parse_url($_POST['url'])) || !isset($parts['host'])) die('ERROR: The specified URL is invalid');
        $url = (isset($parts['scheme']) && $parts['scheme']) ? $parts['scheme'].'://' : 'http://';
        if (isset($parts['user']) && $parts['user']) {
          $url .= $parts['user'];
          if (isset($parts['pass']) && $parts['pass']) $url .= ':'.$parts['pass'];
          $url .= '@';
        }
        $url .= $parts['host'];
        if (isset($parts['port']) && $parts['port']) $url .= ':'.$parts['port'];
        $url .= (isset($parts['path']) && $parts['path']) ? $parts['path'] : '/';
        if (isset($parts['query']) && $parts['query']) $url .= '?'.$parts['query'];
        if (isset($parts['fragment']) && $parts['fragment']) $url .= '#'.$parts['fragment'];
    
        print("Fetching file '$url' to '$filePath'<br />\n");
    
        // Open a local file point in write mode
        if (file_exists($filePath)) die("ERROR: The file '$filePath' already exists");
        $fp = fopen($filePath,'w') or die("ERROR: Could not open local file '$filePath' for writing!");
    
        // Let's go cURLing...
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 50);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_ENCODING, "");
        curl_exec($ch);
        $fileSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
        $fileType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        $transferTime = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
    
        print("cURL operation complete (took $transferTime seconds)<br />\n");
    
        // Close cURL and the local file pointer, we're done with them both
        curl_close($ch);
        fclose($fp);
    
        // Check the $fileSize reported by cURL is the same as the file size on disk
        if ($fileSize != ($fs = filesize($filePath))) {
          print("WARNING: file size reported by cURL ($fileSize bytes) does not match size of file on disk ($fs bytes)<br />\nUsing size of file on disk for DB insert<br />\n");
          $fileSize = $fs;
        }
    
        include ('db.php');
        $query = "INSERT INTO upload2 (name, size, type, path ) ".
        "VALUES ('".mysql_real_escape_string($fileName)."', '$fileSize', '$fileType', '".mysql_real_escape_string($filePath)."')";
    
        print("Running MySQL Query: $query<br />\n");
    
        mysql_query($query);
        mysql_close($conn);
    
        print('Done!');
    
      }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can share files using Shared Folders in Virtual PC, but
[edit] I can delay all mail using delayed_job plugin on a shared server with
Today we're using a shared SQL Server database and that is perfect as I
I built a client server application using posix shared memory and posix unnamed semaphores
I'm trying to build a client server application using POSIX shared memory and POSIX
I am using a shared hosting service to host my site so I can't
How can I save data in unpublic google spreadsheet in PHP without using Zend
I am hosting my website on a shared server, with a mysql database which
I am using shared server with a php script that sends a number to
I started up my local MYSQL server with the shared memory protocol turned on.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.