/    Sign up×
Community /Pin to ProfileBookmark

GET/POST problem

Hi all,

I cobbled together a form that calls a script to upload pictures to a website. The script was working well until I tried to put it up online.

Apparently the hosting company my client uses wont allow the POST method.
Could someone show me how to rewrite my script as to use GET instead of POST?
Heres the simple form

[code]
<form enctype=”multipart/form-data” action=”addindextop.php” method=”GET”>
<input type=”file” name=”photo” />
<input type=”submit” value=”Upload” />

</form>
[/code]

And heres the script

[code]
<?php

error_reporting (E_ALL ^ E_NOTICE);
//This is the directory where photos will be saved

$target = “indextop/”;
$target = $target . basename( $_FILES[‘photo’][‘name’]);

//This gets all the other information from the form
$photo=($_FILES[‘photo’][‘name’]);

// Connects to your Database
include’db_connectcm.php’;

//Writes the information to the database
mysql_query(“INSERT INTO `indextop`(indexphoto) VALUES (‘$photo’)”);

//Writes the photo to the server
if(move_uploaded_file($_FILES[‘photo’][‘tmp_name’], $target))
{

//Tells you if its all ok
echo “The file “. basename( $_FILES[‘uploadedfile’][‘name’]). ” has been uploaded, and your information has been added to the directory”;
header(“location: index.php”);
}
else {

//Gives and error if its not
echo “Sorry, there was a problem uploading your file.”;
}
?>
[/code]

Ive been stuck on this for a while now. Im sure its something simple and any help would be greatly appreciated!

EDIT: It appears ive been wrong.
Aparently this error occurs when trying to POST to a HTML file but the script im calling is actually named .php, Any ideas why im getting this error?

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 29.2011 — I would start by making sure your hosting plan includes PHP. Assuming it does, check with your host's customer support to find out if they need to change your configuration, or if not what it would take to add PHP support.

PS: You will have to use method="post" if you want to do a file upload, as get method HTTP requests have a relatively limited number of bytes that can be transmitted (generally in the 1K to 2K range), besides the fact that post probably makes more sense anyway since you are presumably posting data that will have an effect on something else (file system, database, etc.), where as get requests should not (essentially be read-only).
Copy linkTweet thisAlerts:
@jimmygauthorMar 29.2011 — Thank you for your reply, much appreciated!

You were right about needing PHP activated, Ive done that now.

Unfrtunately I keep receiving this error
<i>
</i>Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


Im sorry to bother you again but any ideas?
Copy linkTweet thisAlerts:
@NogDogMar 29.2011 — You need to look at your db_connectcm.php file and ensure you are using the correct mysql_connect() values.
×

Success!

Help @jimmyg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...