| | |
Python and PHP integration help: Incorrect Image URL decode?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 0
Hello there everyone. For a summer project I'm doing, I have to use a phone to pass an image I've taken (on the phone) to a dedicated server I've made on a local ubuntu machine. For the upload code, I decided on python (seeing on how its easy to learn, and already on the phone), and for the server code I decided on PHP (that was also an easy decision). The problem I keep running into involves the image display: the data seems to be passed through to the PHP code allright, but when I try and display it on the server, this error pops up: "The image...cannot be displayed, because it contains errors. I think this has to do with incorrect decoding of the image data (or incorrect file writing), but so far I haven't been able to come up with a solution. Any help would be great!
Here is the upload code in python:
####
###
And here is the PHP code that it connects with
###
...
##
On an additional note, I also wrote some HTML code that feeds directly into the PHP file, and the images that I recieve through this method are fine, and display without any problems (this is what led me to believe the problem lied in the encoding part in the first place).
Thanks for the help!
Andrew
Here is the upload code in python:
####
PHP Syntax (Toggle Plain Text)
import httplib, urllib f = open(r"/home/cens/einstein.gif",'rb') #test image params = urllib.urlencode({'image': f.read() }) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "image/gif"} conn = httplib.HTTPConnection("pytest.no-ip.info") conn.request("POST", "/upload.php", params, headers) response = conn.getresponse()
And here is the PHP code that it connects with
###
...
PHP Syntax (Toggle Plain Text)
Code: ( text ) $uploaddir = '/home/cens/www/uploads/'; echo '<pre>'; $uploadfile = $uploaddir . "new.gif"; $imgcontent = urldecode($_POST['image']); $fh = fopen($uploadfile, 'wb') or die("can't open file"); fwrite($fh, $imgcontent); fclose($fh);
On an additional note, I also wrote some HTML code that feeds directly into the PHP file, and the images that I recieve through this method are fine, and display without any problems (this is what led me to believe the problem lied in the encoding part in the first place).
Thanks for the help!
Andrew
Last edited by Tekmaven; Jul 24th, 2008 at 3:20 am. Reason: Code tags
•
•
•
•
Hello there everyone. For a summer project I'm doing, I have to use a phone to pass an image I've taken (on the phone) to a dedicated server I've made on a local ubuntu machine. For the upload code, I decided on python (seeing on how its easy to learn, and already on the phone), and for the server code I decided on PHP (that was also an easy decision). The problem I keep running into involves the image display: the data seems to be passed through to the PHP code allright, but when I try and display it on the server, this error pops up: "The image...cannot be displayed, because it contains errors. I think this has to do with incorrect decoding of the image data (or incorrect file writing), but so far I haven't been able to come up with a solution. Any help would be great!
Here is the upload code in python:
####
###PHP Syntax (Toggle Plain Text)
import httplib, urllib f = open(r"/home/cens/einstein.gif",'rb') #test image params = urllib.urlencode({'image': f.read() }) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "image/gif"} conn = httplib.HTTPConnection("pytest.no-ip.info") conn.request("POST", "/upload.php", params, headers) response = conn.getresponse()
And here is the PHP code that it connects with
###
...
##PHP Syntax (Toggle Plain Text)
Code: ( text ) $uploaddir = '/home/cens/www/uploads/'; echo '<pre>'; $uploadfile = $uploaddir . "new.gif"; $imgcontent = urldecode($_POST['image']); $fh = fopen($uploadfile, 'wb') or die("can't open file"); fwrite($fh, $imgcontent); fclose($fh);
On an additional note, I also wrote some HTML code that feeds directly into the PHP file, and the images that I recieve through this method are fine, and display without any problems (this is what led me to believe the problem lied in the encoding part in the first place).
Thanks for the help!
Andrew
How are you displaying the image? Could you post the code for that?
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Other Threads in the PHP Forum
- Previous Thread: E-Mail validation
- Next Thread: Use same part of a variable for two different things
| Thread Tools | Search this Thread |
apache api array basic beginner broken cache cakephp class cms code computing confirm countingeverycharactersfromastring cron curl customizableitems database date delete dynamic echo email error fcc file filter folder form forms forum freelancing function functions gc_maxlifetime google header headmethod howtowriteathesis href htaccess html iframe image include incode ip javascript joomla limit link login malfunction match memmory memory menu method mod_rewrite multiple mysql navigation neutrality oop pagerank parsing paypal pdf php phpmysql query question random recursiveloop root script search select server sessions sms snippet soap source space sql support! system table template thesishelp trouble tutorial upload url variable video web window.onbeforeunload=closeme; youtube






