Jump to content

How to create a php that uses $GET to upload image to server


franziss

Recommended Posts

I need to upload an image using php and store the image as blob in mysql. I understand the standard way is to create a form for the user, let the user choose the image to upload, click submit.

 

But I need to create a php, for example, uploadImage.php?image="c:\myPhoto.jpg"

and when I type http:\\www.myhome.com\uploadImage.php?image="c:\myPhoto.jpg"

from a web browser in my pc, I can automatically upload myPhoto.jpg to the myhome.com server?

 

Thank you for your kind help.

Link to comment
Share on other sites

I tried the following code in uploadImage.php

 

$image = $_GET['image'];
$handle = fopen($image, "rb");

 

but it doesn't work. Is it that fopen will try to locate the this image in the server and not the client PC?

 

I am thinking of another way to do this:

 

Call http:\\www.myhome.com\uploadImage.php?image="c:\myPhoto.jpg"

 

In uploadImage.php do

Step 1. $image = $_GET['image'];

Step 2. pass $image into a form in uploadImage.php

Step 3. Call a javascript in uploadImage.php to submit this form

Step 4. Image is uploaded to the server.

 

Do you think this is feasible? Thank you.

Link to comment
Share on other sites

I found a solution from the internet, which uses curl with php, but it only works if the file to be uploaded is in the same location as the server.

 

In the code below, the image I want to upload is from the client PC, c:\a.jpg, but it does not work. Anybody has any suggestion? Thanks!

 

<?php
// URL on which we have to post data
$url = "http://home.com/processImage.php";

// File you want to upload/post
$post_data['file'] = "@c:/a.jpg";

// Initialize cURL
$ch = curl_init();
// Set URL on which you want to post the Form and/or data
curl_setopt($ch, CURLOPT_URL, $url);
// Data+Files to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// Pass TRUE or 1 if you want to wait for and catch the response against the request made
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// For Debug mode; shows up any error encountered during the operation
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Execute the request
$response = curl_exec($ch);

// Just for debug: to see response
echo $response;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.