Page 1 of 1
trouble uploading images w/ form
Posted: Fri Feb 04, 2011 1:05 pm
by someguyhere
I've looked at several tutorials on uploading files to a server via php but I can't seem to get it to work. Can someone point me to a decent tutorial for this? I need to upload two images to a particular folder, and I'll be adding additional fields (text) later.
I've done far more complex things than this, but for some reason, I seem to have the logic of a drunk toddler on this one
Any help is greatly appreciated.
Re: trouble uploading images w/ form
Posted: Fri Feb 04, 2011 1:07 pm
by litebearer
do you have some code to show us where you experiencing problems?
Re: trouble uploading images w/ form
Posted: Fri Feb 04, 2011 1:47 pm
by someguyhere
Here's what I've got so far. It's modified from something I found online, but even if/when I do get it working, the other issue is that I will need to add one more image upload to this form which I can't see how to do.
Code: Select all
<?php
if (isset($_POST["logo"])){
$target = "/wp-content/plugins/wp-members-pages/images/";
$target = $target . basename( $_FILES['logo']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['logo']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
}
if (empty($_POST["logo"])){
echo '<form action="" method="post" >';
echo '<input name="logo" type="file" />';
echo '<input type="submit" value="Upload" />';
echo '</form>';
}
?>
Re: trouble uploading images w/ form
Posted: Fri Feb 04, 2011 1:58 pm
by litebearer
Re: trouble uploading images w/ form
Posted: Sat Feb 05, 2011 9:31 am
by someguyhere
I used the one you linked to with some modifications. Still no dice though. When I click submit, all it will do for me is refresh to the form again, but it doesn't give me a message saying either that the file has been uploaded or has failed to upload.
Code: Select all
<?php
if (isset($_POST["uploadedfile"])){
// Where the file is going to be placed
$target_path = "/test/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = "/test/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
if (empty($_POST["uploadedfile"])){
echo '<form enctype="multipart/form-data" action="" method="POST">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="100000" />';
echo '<input name="uploadedfile" type="file" />';
echo '<input type="submit" value="Upload File" />';
echo '</form>';
}
?>
Re: trouble uploading images w/ form
Posted: Sat Feb 05, 2011 5:47 pm
by someguyhere
Anyone?