Page 1 of 1
Upload using php5
Posted: Sun Mar 01, 2009 7:29 pm
by shirkavand
hi there,
I want to make an upload file page using php5 full object oriented code, i have my html code like this:
<form action="upload_ready.php" method="post" enctype="multipart/form-data">
...
...
<input type="file" name="photoupload" id="demo-photoupload" />
...
...
</form>
In my "upload_ready.php" i want to have a full OO code, liske so:
class upload_ready
{
//So here i can access the uploaded file, save it etc etc
}
Whatever i do i can not make this work properlu, is this possible? Any idea, suggestion will be apreciated.
Regards
Re: Upload using php5
Posted: Sun Mar 01, 2009 10:44 pm
by requinix
Of course it doesn't work properly - there isn't any code!
Re: Upload using php5
Posted: Mon Mar 02, 2009 12:07 am
by shirkavand
tasairis wrote:Of course it doesn't work properly - there isn't any code!
Hi there,
Oops, yes! i forget about posting rules, sorry about that.
Ok, here is my code, note: if i do not use the "$something = new upload_ready();"(line number 3) nothing works otherwise everything works fine. But if you see carefully that line(number 3) is not into an object, class or something, that is my question, how can i create upload_ready.php using full OO php aproach?
Code: Select all
<?php
$something = new upload_ready();
class upload_ready
{
private $result;
function upload_ready()
{
$this->result = array();
$this->upload();
}
private function upload()
{
if (isset($_FILES['photoupload']) )
{
$file = $_FILES['photoupload']['tmp_name'];
if (!is_uploaded_file($file) || ($_FILES['photoupload']['size'] > 30 * 1024 * 1024) )
{
$error = 'Please upload only files smaller than 2Mb!';
}
$log = fopen('script.log', 'a');
fputs($log, " {$_FILES['photoupload']['name']} - {$_FILES['photoupload']['size']} byte\n" );
fclose($log);
}
else
{
$result['result'] = 'error';
$result['error'] = 'Missing file or internal error!';
}
if (!headers_sent() )
{
header('Content-type: application/json');
}
echo json_encode($result);
}
}
?>
regards
Re: Upload using php5
Posted: Mon Mar 02, 2009 12:09 am
by Benjamin
Please use the appropriate
Code: Select all
[ /code] tags when posting code blocks in the forums. Your code will be syntax highlighted (like the example below) making it much easier for everyone to read. You will most likely receive more answers too!
Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces. You can even start right now by editing your existing post!
If you are new to the forums, please be sure to read:
[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]
If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online. You'll find code samples, detailed documentation, comments and more.
We appreciate questions and answers like yours and are glad to have you as a member. Thank you for contributing to phpDN!
Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Re: Upload using php5
Posted: Wed Mar 04, 2009 7:52 pm
by shirkavand
Hi,
Can somebody help me with this?
Thanks
Re: Upload using php5
Posted: Wed Mar 04, 2009 8:35 pm
by requinix
shirkavand wrote:Ok, here is my code, note: if i do not use the "$something = new upload_ready();"(line number 3) nothing works otherwise everything works fine. But if you see carefully that line(number 3) is not into an object, class or something, that is my question, how can i create upload_ready.php using full OO php aproach?
You
are.
If I want to drive somewhere in my car I actually have to
drive my car. Same way with objects: you can't expect it to do something unless you actually tell it to do something. That's what happens on line 3.