<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1040026" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1040026</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/can-someone-tell-me-how-make-image-upload-script#comment-1227173</link>
    <description> &lt;p&gt;There are a lot of good Imageshack.us clones and such on the net. SOme are paid, some are free. I once had one really good, but decided to not create that site..&lt;br /&gt;
I see that you want to code it yourself, but ready made ones would be good too..&lt;/p&gt;
 </description>
     <pubDate>Mon, 10 Dec 2007 18:50:35 +0000</pubDate>
 <dc:creator>LosKas</dc:creator>
 <guid isPermaLink="false">comment 1227173 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/can-someone-tell-me-how-make-image-upload-script#comment-1226344</link>
    <description> &lt;p&gt;Ok I have a basic file upload script, but still not sure how to do the folder thing you described, also this doesn&#039;t seem to work does there need to be some sort of permissions that allow files to be uploaded? Also, where does allowing only JPEG, GIF etc come into this code?&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;upload&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] == &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$to &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;uploads/&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;file&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;name&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;move_uploaded_file&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;file&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;tmp_name&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$to&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;Uploaded&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
 </description>
     <pubDate>Wed, 14 Nov 2007 13:54:52 +0000</pubDate>
 <dc:creator>drew22299</dc:creator>
 <guid isPermaLink="false">comment 1226344 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/can-someone-tell-me-how-make-image-upload-script#comment-1226018</link>
    <description> &lt;p&gt;I wouldnt save the images into MYSQL&lt;br /&gt;
It&#039;s not a problem as such, I just think it&#039;s better to be on the server hard drive as a standard &#039;file in folder&#039;&lt;/p&gt;
&lt;p&gt;to be honest me giving you the best option for your site is too hard, I dont know how your site works, how many members etc&lt;/p&gt;
&lt;p&gt;a good all round method is :&lt;br /&gt;
the end result on your server will be this:&lt;br /&gt;
/user_images / year_month / username / file&lt;/p&gt;
&lt;p&gt;make a new folder on your server...&quot;user_images&quot; (whatever)&lt;/p&gt;
&lt;p&gt;FILENAME:&lt;br /&gt;
you can use the filename of the image they are uploading &lt;/p&gt;
&lt;p&gt;FOLDER&lt;br /&gt;
make a new field in the DB called &quot;foldername&quot;&lt;br /&gt;
this is going avoid you having many sub_folders in a single folder&lt;/p&gt;
&lt;p&gt;SO&lt;br /&gt;
when user goes to the upload form and chooses an image and clicks GO&lt;/p&gt;
&lt;p&gt;script checks the server to see if the folder exists &lt;/p&gt;
&lt;p&gt;$date = current month and year&lt;br /&gt;
(result has to look like this nov2007)&lt;/p&gt;
&lt;p&gt;IF EXISTS - /user_images / $date / $username /&lt;br /&gt;
delete the current file from in there (as you only allow one file) then write the new file to it&lt;br /&gt;
(it did exists so there is a file there and they want to overwrite with a new image, so delete current one and write new, and of course there will be a db reference)&lt;/p&gt;
&lt;p&gt;ELSE&lt;br /&gt;
create the folder name it $date, then write the file to it, then write that $date into the users row in fieldname &quot;foldername&quot; in the DB&lt;/p&gt;
&lt;p&gt;when you come to display the users image&lt;br /&gt;
query the DB, get the row where the username matches the username, select the &quot;foldername&quot; field&lt;br /&gt;
then&lt;br /&gt;
$file_location = /user_images / $row[&#039;foldername&#039;] / $username&lt;/p&gt;
&lt;p&gt;get the file from in there (there should only be one) and display it&lt;/p&gt;
&lt;p&gt;NOTE&lt;br /&gt;
You could create the folders manually, it sounds like a pain, but creating 12 folders (one for each month) and you are set for a year&lt;br /&gt;
I suggest that, just incase on the offchance that two people are creating a file at the same time&lt;br /&gt;
both hit the server at same time and folder doesnt exist (eg dec2007)&lt;br /&gt;
so one makes the folder, then the next one tries to make folder and error already exists&lt;br /&gt;
and if you do this, make sure on the db check and server check if the folder exists you MUST have the server check first&lt;br /&gt;
if you have made the folder manually, it wont be in the users DB &quot;foldername&quot;&lt;br /&gt;
so if DB check is first, it will check DB, not find anything and then try to make the folder, which already exists as you made it&lt;/p&gt;
&lt;p&gt;you could allow users to choose their own filename, but you will need to get the extension of the file first so you can merge their chosen filename with the extension and then save it&lt;/p&gt;
&lt;p&gt;again it&#039;s really up to you to decide whats best for your site, if you only have a handful of members you dont need a folder naming system as there wont be many folders/files&lt;br /&gt;
and without the DB reference is faster, as there is no db query it simply goes straight to their folder- so use my last post example&lt;/p&gt;
&lt;p&gt;you will also need other checks too&lt;br /&gt;
max filesize - whatever you want to allow max to be&lt;br /&gt;
you also only want to allow certain types of extension...gif, jpg etc&lt;/p&gt;
&lt;p&gt;and really a MUST is to check the mime type&lt;br /&gt;
as exploits can be made easily without checking if the file really is an image&lt;br /&gt;
someone could make a php exploit script file, save it as a jpg and upload it&lt;br /&gt;
there are some ways around it even then, but this makes it a lot harder&lt;/p&gt;
 </description>
     <pubDate>Mon, 05 Nov 2007 14:27:43 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1226018 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/can-someone-tell-me-how-make-image-upload-script#comment-1226016</link>
    <description> &lt;p&gt;Thanks for your quick reply, the folder idea sounds good but as you said if there are alot of users it might become slow. At the moment its a basic site where people register and have their own profile, other members can send messages to each other, add to their friends list and browse members. I just need to allow users to upload one pic, which will appear on their profile and maybe on other pages such as in search results.&lt;/p&gt;
&lt;p&gt;With the folder idea will the image be overwritten when the user uploads a different pic every time? (since they are only allowed one pic this is what I need)&lt;/p&gt;
&lt;p&gt;Do you know how to insert pics into a database? I&#039;m guessing that would be more secure? and quicker if there were alot of pics?&lt;/p&gt;
 </description>
     <pubDate>Mon, 05 Nov 2007 10:32:40 +0000</pubDate>
 <dc:creator>drew22299</dc:creator>
 <guid isPermaLink="false">comment 1226016 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/can-someone-tell-me-how-make-image-upload-script#comment-1225938</link>
    <description> &lt;p&gt;Is it only one image per user?&lt;br /&gt;
if yes, and I presume duplicate usernames are not allowed, then one option is ....&lt;br /&gt;
create a subfolder on the server called user_images (or whatever)&lt;/p&gt;
&lt;p&gt;when the user uploads an image, have the PHP create a sub-folder on the server in the &quot;user_images&quot; folder&lt;br /&gt;
name it the users username&lt;br /&gt;
then name the filename the user name&lt;br /&gt;
I&#039;m guessing where the image is going, but if say it&#039;s for a forum for an avatar, when the avatar is drawn make the &lt;img url=&quot;the&quot; usernames folder and file both named the eg img url=&quot;/user_images/&amp;#039;.$username.&amp;#039;/&amp;#039;.$username.&amp;#039;&quot; /&gt;&lt;br /&gt;
that isnt exact but gives you the general idea&lt;/p&gt;
&lt;p&gt;so you dont need DB references at all&lt;br /&gt;
and the script for that is very simple&lt;br /&gt;
a form to upload a file, the page the form goes to simply creates a folder with the username and a file with the username&lt;/p&gt;
&lt;p&gt;you will of course on the form process page need to check for a few things&lt;br /&gt;
you will want to limit file sizes, and perhaps have some sort of rescaling of the images, again i don&#039;t know what you really want it for&lt;/p&gt;
&lt;p&gt;word of warning though, if you anticipate many users uploading images, that folder (user_images) will start to have many sub folder in it&lt;br /&gt;
It&#039;s not good practice to have too many folders in one folder&lt;br /&gt;
so then you might want to create sub folders by something else&lt;br /&gt;
perhaps users register date&lt;br /&gt;
so have the script create a sub-folder for each month, or sets of 3 or 4 months&lt;br /&gt;
this all depends on how many users you have and how many of them you expect to upload images&lt;/p&gt;
&lt;p&gt;if you give more info about the site and what/where the images are to be used I can suggest a more precise option for your circumstance and maybe provide some code if you can&#039;t do it yourself from scratch&lt;/p&gt;
 </description>
     <pubDate>Fri, 02 Nov 2007 15:53:32 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1225938 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
