Login   Register  
PHP Classes
elePHPant
Icontem

[New Fuction] add new function input type="file"

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Auto form  >  All threads  >  [New Fuction] add new function input type="file"  >  (Un) Subscribe thread alerts  
Subject:[New Fuction] add new function input type="file"
Summary:[New Fuction] add new function input type="file"
Messages:14
Author:Mohamed Ziata
Date:2013-03-03 17:16:30
Update:2013-03-14 20:36:39
 
  1 - 10   11 - 14  

  1. [New Fuction] add new function input type="file"   Reply  
Picture of Mohamed Ziata
Mohamed Ziata
2013-03-03 17:16:30
Plz add new function (input type="file") in your clsse because that function is highly recommended.

  2. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Arturs Sosins
Arturs Sosins
2013-03-04 08:03:36 - In reply to message 1 from Mohamed Ziata
You see the real point of class, to automatically match an input based on mysql table data.
So while it is possible to implement file input, but what file type in database should it match?

BTW you can also provide it as a custom_html pretty easily ;)

  3. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Mohamed Ziata
Mohamed Ziata
2013-03-07 15:08:23 - In reply to message 2 from Arturs Sosins
If I understand what you say, do not stop to think.

Regarding custom_html I miss but I have two problems:

PROBLEM 1 - With custom_html I get double the input (like the image down). But you can fix this by hiding the input.

[IMG]http://i48.tinypic.com/wtjrd.png[/IMG]

PROBLEM 2 - I want the form to have the option to upload an image, but using custom_html gives me the following array:

[CODE]
array ['img'] = "name_img.png"
[/ CODE]

but it should give me the following array to a file:

[CODE]
array ['img'] ['tmp_name'];
array ['img'] ['size'];
array ['img'] ['type'];
array ['img'] ['name'];
[/ CODE]

The question is how do I save the image if I don't have the correct array?

This is one pice od my code [URL]http://pastebin.com/4utQ5kmd[/URL]

  4. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Arturs Sosins
Arturs Sosins
2013-03-07 15:42:25 - In reply to message 3 from Mohamed Ziata
Oh ok, I see the problem, let me test it and see what I can do! ;)

  5. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Mohamed Ziata
Mohamed Ziata
2013-03-07 16:49:30 - In reply to message 4 from Arturs Sosins
Thanks, I'll be waiting. If you need my code let me know.

  6. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Arturs Sosins
Arturs Sosins
2013-03-10 08:18:31 - In reply to message 5 from Mohamed Ziata
Hello,
sorry for late reply, but weekend plans never go as planned :)

So back to your issue.
1) the doubled input appears because you already have a field with that name in database. Custom HTML does not override default fields, but default fields can be excluded like this:

//exclude table columns
$ex = array("ID", "imgTextured");
$form->insert_form("test_table", $ex);

2) Then you need to provide modification method to handle the o,age and retrieve the path of the image and put it in your form array like this:

function prepare_image($arr) {
$newpath = "upload/" . $_FILES["imgTextured"]["name"];
move_uploaded_file($_FILES["imgTextured"]["tmp_name"], "upload/" . $_FILES["imgTextured"]["name"]);
$arr["imgTextured"] = $newpath;
return $arr;
}

$form->set_modification("prepare_image");

3) Then you can add custom validation, where you validate your image like you did before

Of course for security and efficiency reasons, you can merge step 2 and 3 by validating image before uploading it and either populate "imgTextured" or not (if image is invalid, you will not provide a value to "imgTextured", but since it will probably be required in your database form class will still display a form input error)

4) one last thing to do, is to modify auto_form.php a bit and on line 708
$this->forms[$count]["html"] = "<form id='".$table_name."_".$count."' method='post' action='' enctype='multipart/form-data'> \n";

add the enctype='multipart/form-data' part to accept file upload

Cheers ;)

  7. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Mohamed Ziata
Mohamed Ziata
2013-03-11 21:31:14 - In reply to message 6 from Arturs Sosins
Thanks Arturs Sosins :-), changing the code to me there is a new error:

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Here I am attaching my code to help me please, I can not find the problem. Is that this is the single quotes, but not where. :-S

ZIP my code: http://bit.ly/15ImbfY

Scanning Zip: http://bit.ly/Zgfqyf

  8. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Arturs Sosins
Arturs Sosins
2013-03-13 11:08:46 - In reply to message 7 from Mohamed Ziata
Now I understand that documentation should probably be more thorough :)

Well the problem is, that (at least I always used) only one modification method and do all modifications inside it, I did not anticipate that there could be multiple modification functions. And modification function must always return received array (modified or not but it should be the same array)

Correcting all that made your code work for me ;)

  9. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Mohamed Ziata
Mohamed Ziata
2013-03-13 12:36:33 - In reply to message 8 from Arturs Sosins
If I understand correctly, your classe that uses TO does not currently support more than 1 time function set_modification().

What do I do?
A) Change my code to suit your classe?
B) or wait for you to adapt your class for which you can use more than 1 time function set_modification()?

  10. Re: [New Fuction] add new function input type="file"   Reply  
Picture of Arturs Sosins
Arturs Sosins
2013-03-13 21:49:02 - In reply to message 9 from Mohamed Ziata
I've updated the class right now, so you can download and try it out ;)

 
  1 - 10   11 - 14