franziss Posted March 25, 2011 Share Posted March 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231666-how-to-create-a-php-that-uses-get-to-upload-image-to-server/ Share on other sites More sharing options...
MrXHellboy Posted March 25, 2011 Share Posted March 25, 2011 It would be possible to cheat i guess if you did not check for things and put some security into your script. Quote Link to comment https://forums.phpfreaks.com/topic/231666-how-to-create-a-php-that-uses-get-to-upload-image-to-server/#findComment-1192068 Share on other sites More sharing options...
franziss Posted March 25, 2011 Author Share Posted March 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231666-how-to-create-a-php-that-uses-get-to-upload-image-to-server/#findComment-1192071 Share on other sites More sharing options...
franziss Posted March 31, 2011 Author Share Posted March 31, 2011 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/231666-how-to-create-a-php-that-uses-get-to-upload-image-to-server/#findComment-1194856 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.