cakephp set field in this->data to a related field in database - php

I am trying to upload multiple images using meioupload which works fine if I set image.1.field and then image.2.field for each field of data. Then loop through and create/save rather than saveall.
My problem comes when I have field which is used as a subfolder for the image within an images folder.
for example I have a form
image.1.product id
image.1.artist
image.1.file to upload
image.2.product id
image.2.artist
image.1.file to upload
now when the items are saved, all data is correct including the belongsto relationship of product id, except the second image is stored in the wrong place.
The first image is stored in images / image.1.artist / file
the second image is stored in images / image.1.artist / image.2.artist / file
This is extremely annoying, and it is simply someting to do with the way the meioupload behaviour sets the subfolder to be a field from the array.
The way I have had to resort to saving the data is by looping through and creating then saving the values, which isnt a problem, but it obviously doesnt work with this method of setting a sub folder.
So a solution could possibly be to simply set the second artist field as blank and only add multiple images for the same artist..
Or to set the data field of artist to the actual field of artist in the related product the image will belong to, but I can't seem to get this to work?
So the question is how can I set the value of this field to the related products artist field that is already in the database for each seperate create/save?
ps. I am sorry if this is a bit long winded.

Right so the problem came because I was sending $this->data as 2 arrays. The solution was to read this->image->product->field('artist') and set it to this->data['Image'][1]['artist'].
This way it sets the field in the first array to artist, which in this particular meioupload behaviour will roll over to the second array of data and hence the image upload (which will then be suffixed with a /) This allows me to upload the images to their corresponding artist directory whilst creating 3 thumbnails and saving the relations, file info and so on.
I found that this doesn't seem to make a difference to loading the images (images work fine even though the display code effectively has two / in it, because the second image will be saved in the database as /dir/artist/ as a pose to the first one which is saved /dir/artist)
IF anyone has an ingenious way to call meioupload one at a time then this would hopefully avoid this slight issue, and then more and more images could be added into the same form..alas I am not clever enough to know how to do this yet..
Any help would be much appreciated!!!!

Related

Laravel 4 - Model relations for Posts with multiple Image Uploads

How would you set this up?
Each Post has one Image (which can have a title/caption/etc) and each Image has multiple Uploads (different image sizes).
I've got a working setup for this going right now using pivot tables and model relations but it's not very pretty to query the data with these uploads... I just wanted to take a step back for a moment here and ask how another person out there would approach this?
I want to use eloquent to simply grab the Post Object with all of it's associated images and their uploads included.
Here's a screenshot of my full current db schema in case you're interested:

PyroCMS - Pyrostreams multiple file upload on one entry

I've got the PyroStreams module for PyroCMS and made a stream called portfolio. Everything is working as expected, however it only allows to upload just one image for my file field. That is obvious, but I'd like to know if there's a way to upload multiple images for one stream entry without adding x number of extra file fields. Or do I need to code an extra field type myself to support this? Maybe someone's got it already?
Thanks
According to me you have to create a separate database table that will hold all the images those are related to particular portfolio and the portfolio id by id by which you can fetch the images for particular record and then use any multiple image upload library like http://www.plupload.com/example_queuewidget.php to upload multiple images in the portfolio image table. Hopefully this will help you in achieving what you want.
There's a multi-upload files field type available on the pyrostore.

Cycling through mysql data?

I am creating a website for funny images. Those images are stored in a file in the server. I have a database that contain all the information for all of those images (name in the file, type, views, likes, dislikes, reports, and so on).
I want to use the name of that image as my url www.example.com/name_of_the_image and when I click on the image it will take me to the next (image page) so each image will have its own unique url.
I already tried to pass the id of the image from the database to the url and keep browsing the images but it seemed unprofessional way to do what I want to achieve.
Now what is the best and efficient way to do this ? Any ideas ?
use ’slugs’.
have an extra field with your database image data called slug.
everytime you upload an image store it using the slug(usually a slug is the title in lowercase with underscores instead of spaces).
Then use .htaccess to rewrite your urls to something pretty that uses the slug to retrieve the info.
www.host.com/images/cat_in_a_pickle_jar
points to
www.host.com/displayimage.php?slug=cat_in_a_pickle_jar

upload image, then put file path into a form

I just need a bit of advice on what direction to go with something I am creating.
It is a simple php based webpage for our sports and social members in our office, allowing them to create, edit, view and delete events for all members to see. Events like day trips, bbq's and all kinds of things like that.
So far I have it all working as I would like, other than one thing, being the event logos.
At present, the events are all stored in a mysql database, in one table, with a column for every aspect of the event; time, date, price, venue etc etc.
I also have two columns for the event logos, one for the venue logo, and one for the general event logo.
What I need advice on, is the best way to create a page that allows a user to upload an image to the server, browse the images already uploaded, select one, and have it's file path entered into a text input when creating the event.
Could someone offer their suggestions on the best way to go about this, or offer an alternative method for selecting and inputting a logo for the event?
Thanks
The Uploadify jQuery plugin works really well for batch and/or AJAX uploads. The way I'd handle your situation would be this:
Show all images on the same page with the form, and give each image a related radio button with the image path as the button's value, so the user simply checks the image they want to use,
If the user wants to upload images, use the Uploadify plugin and it's AJAX callback functions to dynamically populate the existing list of radio buttons.
The comment I made on your question, asking wether you store images (or their file paths) was because I think it would be much easier (and cleaner) for you to retrieve a list of uploaded images by querying a database. Personally, I don't store images in a database, only their file paths, and use PHP to handle any images that need to be deleted or moved. It's easier to assing images to other entities (especially in many-to-many relationships) that way.
If you don't want to store images' data in a separate table, I guess you'd have to use PHP file system functions to get a list of files already uploaded (glob comes to mind, although there could be better functions or this).
EDIT:
There is also a very good AJAX file browser plugin - ckFinder, but I have very little experience with it and can't really comment on its workflow, but if you find it to be a more elegant solution, you should try it out.
if i could understand your question you want to associate the image with the event i.e tag the image with the event right ??
you can use jquery's attr() function to grab the src of img and put it in input field
I ended up storing the images in the database itself.
Saved some hassle on the file path side of things.

How to store multile images full path into a database so that I can display them in a user home page like Orkut

I am making an application in which every user has to sign in first and then he can access his home page. Now on the home page, I have given an option of uploading an image. Now if the user is uploading one image I am storing the full path of the uploaded image into a database and from there I can display the image easily by an img tag...
But what should I do when the user want to upload many images? Then how should I store their full paths in a database for the same user. Give me an idea just like Orkut or Facebook. Should I make a different table with named images and should I store images in different rows with the same username. What should I do?
I don't know the logic. What should I do? How can I upload many images and how can I store their path and what will be the wisest method and how do I display many images on one page (I can display one)?
You can make a folder, named after user name and id and put all their images there.
To display many images on one page, just add more <img> tags to the page.
This seems to be more of a design question than a PHP question. I would create a separate table to store all paths, this is more normalized.
You still need to handle the UI, but if you are doing a sort of gallery then that is fairly simple with some jQuery sideshows or something like that.
Yes, you want to use a separate table to store the image paths. You'll most likely want a record ID, the User ID, and the path to the image. You could also add a field to contain the sorting order for the images.
Having the sorting order field will allow you to page through the photos if there is more than one page of photos.
Your thinking is correct where you suggest creating a separate table with rows containing the image path and the username. The concept that you are dealing with is called cardinality. I'd recommend that you take a few minutes to read about this concept, since it is so important to database design.
In this case, you're talking about a one-to-many relationship between the user and the images.

Categories