Superian Posted May 16, 2007 Share Posted May 16, 2007 1.)What is the best way to store photos? 2.)Is it possilbe to send photos straight to the database or will have to write a script to grab the file from the temp_file? Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/ Share on other sites More sharing options...
hitman6003 Posted May 16, 2007 Share Posted May 16, 2007 1.)What is the best way to store photos? In files. 2.)Is it possilbe to send photos straight to the database or will have to write a script to grab the file from the temp_file? This question has a yes and no answer. Yes, you can insert them into the database, however, when a file upload occurs php automatically writes it to a temporary file, which is cleaned up automatically after the script concludes execution. So, in order to insert them into a database, you must use one of the file read functions on the file located at the location stored in the 'tmp_name' location in the $_FILES['form_field_array'] array. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-254938 Share on other sites More sharing options...
Superian Posted May 17, 2007 Author Share Posted May 17, 2007 Correct me if I am wrong. I will need to create a script that will upload the file. Write a script that will open the temp_file, grab the file and then store it in the database, correct? If so, what type of field will I need as a database column? Note: I am trying to create a photo ablum. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-255315 Share on other sites More sharing options...
Superian Posted May 17, 2007 Author Share Posted May 17, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-255579 Share on other sites More sharing options...
Superian Posted May 18, 2007 Author Share Posted May 18, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256587 Share on other sites More sharing options...
akitchin Posted May 18, 2007 Share Posted May 18, 2007 i would suggest you save the file via the filesystem (ie. as an actual image file) and store the FILENAME in the database. in this case, it's a matter of setting up its filename, ensuring it's unique, moving the temp file to its final location (move_uploaded_file()), and inserting its entry into the database. have a look in the manual regarding handling file uploads; there's an entire section on it. should give you some good background. if you wanted to save the file as its binary format, you'd need a BLOB column in your table. i've yet to see a situation where this is preferable, though. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256593 Share on other sites More sharing options...
corbin Posted May 18, 2007 Share Posted May 18, 2007 I heavily suggest storing the images in files unless it's a cluster of servers or some other situation.... You would want to store it as the 'blob' type. If you want to use a DB cause you don't know how you would map to the files, you could always just store the image name and then use that file for the id in the DB..... Just a suggestion. Edit: akitchin covered everything I said, but I typed it, so it's gonna be read ;p. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256596 Share on other sites More sharing options...
Superian Posted May 18, 2007 Author Share Posted May 18, 2007 I heavily suggest storing the images in files unless it's a cluster of servers or some other situation.... You would want to store it as the 'blob' type. If you want to use a DB cause you don't know how you would map to the files, you could always just store the image name and then use that file for the id in the DB..... Just a suggestion. Edit: akitchin covered everything I said, but I typed it, so it's gonna be read ;p. I am building a photo ablum website. By doing this, I am also trying to save web space during the process. What are the advantages and disadvantages of both storing photos in a file compared to storing photos in a database. Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256602 Share on other sites More sharing options...
hitman6003 Posted May 18, 2007 Share Posted May 18, 2007 They are going to use disk space if they are in the database or on the file system... Generally speaking, if you have a shared hosting solution, they limit you to a very small amount of MySQL space...you may want to check on that. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256613 Share on other sites More sharing options...
Superian Posted May 18, 2007 Author Share Posted May 18, 2007 They are going to use disk space if they are in the database or on the file system... Generally speaking, if you have a shared hosting solution, they limit you to a very small amount of MySQL space...you may want to check on that. Basically, my best option is to create a script that will produce a file for each user and store the photos in their file? Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256619 Share on other sites More sharing options...
hitman6003 Posted May 18, 2007 Share Posted May 18, 2007 i would suggest you save the file via the filesystem (ie. as an actual image file) and store the FILENAME in the database. As akitchin said, store the file, regardless of name, on the file system, then store a reference (the location) to it in the database. Then you can store other metadata, like the owner, in the database and access it easily. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256621 Share on other sites More sharing options...
Superian Posted May 18, 2007 Author Share Posted May 18, 2007 Thanks, to all! Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256627 Share on other sites More sharing options...
Superian Posted May 19, 2007 Author Share Posted May 19, 2007 The question I have now is there a file system that will create a folder for the unique user or will I have to write a script that will handle the creating the folder process? Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256736 Share on other sites More sharing options...
john010117 Posted May 19, 2007 Share Posted May 19, 2007 mkdir() will suit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-256812 Share on other sites More sharing options...
Superian Posted May 24, 2007 Author Share Posted May 24, 2007 I have writting the entire script where the file uploads, validates, and resizes the image. The problem I am facing now is storing the name of the file in the database. How can this be done? // Above is validation and image resize $photo_path = "php_uploads/"; <?php if (file_exists("$photo_path" . $PhotoName)){ echo $PhotoName . " already exists. "; } else{ move_uploaded_file($PhotoTemp, "$photo_path" . $PhotoName); echo "Stored in: " . "$photo_path" . $PhotoName; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-261096 Share on other sites More sharing options...
corbin Posted May 24, 2007 Share Posted May 24, 2007 I would randomly generate image names and store them above the webroot. I would then log the true image name in the database, along with the owner id, owner name, original image name, and the renamed generated name (along with other stuff, but that's just me). Then I would make a simple script that pulled the true image name from the DB and I would output it to the browser. If users log in to view pictures you could make it where it shows their pictures like that and they could use original names, but most likely you would want to give them some ID for the image to view (or just the renamed name). Then that could be plugged in to a url and your script could serve the correct image for that ;p. Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-261118 Share on other sites More sharing options...
Superian Posted May 24, 2007 Author Share Posted May 24, 2007 I would randomly generate image names and store them above the webroot. I would then log the true image name in the database, along with the owner id, owner name, original image name, and the renamed generated name (along with other stuff, but that's just me). Then I would make a simple script that pulled the true image name from the DB and I would output it to the browser. If users log in to view pictures you could make it where it shows their pictures like that and they could use original names, but most likely you would want to give them some ID for the image to view (or just the renamed name). Then that could be plugged in to a url and your script could serve the correct image for that ;p. Would this include the file extension also? If so, what would be the field type and the size of the type? Quote Link to comment https://forums.phpfreaks.com/topic/51752-i-have-a-question-about-file-uploading/#findComment-261138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.