Toon posts:

[php]uploaden en resizen image

Pagina: 1
Acties:
  • 79 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik maak gebruik van een script die afbeeldingen upload en resized...
Helaas loopt dit ergens vast.. , ik krijg deze foutmelding:
Warning: Unable to open none in c:/program files/apache group/apache/htdocs/test/upload/script.php on line 116

Warning: Unlink failed (No such file or directory) in c:/program files/apache group/apache/htdocs/test/upload/script.php on line 165
:(

Nu heb ik eerst naar de rechten van de map gekeken.. deze heb ik op alle rechten gezet !!! met windows.. of moet je Apache ook goed configureren daarvoor.

Het controleren van de extensie etc. gaat wel goed.. als je een ander bestand upload krijg je keurig de melding dat het een jpg moet zijn...

Dit is mijn script wat wordt gebruikt:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?

/*  ====================================================================
*  Copyright (c) 2000 Marcus Kazmierczak, marcus@mkaz.com
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*  1. Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*
*  2. Redistributions in binary form must reproduce the above copyright
*     notice, this list of conditions and the following disclaimer in the
*     documentation and/or other materials provided with the distribution.
*
*  3. The name of the author may not be used to endorse or promote products
*     derived from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
*  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
*  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
*  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
*  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*  ====================================================================
*/


/* 
    SCRIPT CHANGE LOG:

    2002-06-10:

        * Plugged security hole with is_uploaded_file() function. Thanks much 
          to Timothy Rieder for pointing this out.


    2001-01-10:

        * Added line of text letting user know what extension was read in
          when denying a file upload. Suggestion by Sandro Juergensen.


    2001-01-09: 

        * Removed GIF support from script to not encourage the use of
          silly patents. For more info: http://www.gnu.org/philosophy/gif.html

        * Cleaned up the code and comments

        * Moved the extension check out of the size check loop. 
          Thanks Sandro Juergensen <forgetit@sandlatscher.de>

        * Added lower casing the extension check
          
        * Added converting spaces in filename to underscores

    2000-05-31:
        
        * original script released
*/
?>
<html>

<head>
    <title>web.blazonry : PHP : Upload and Resize an Image</title>

<meta name="author" content="Marcus Kazmierczak, marcus@mkaz.com">
<meta name="copyright" content="(c) 2000 mkaz.com">
<meta name="license" content="http://blazonry.com/mklicense.php">
<meta name="origin" content="May 2000">

<?

if ($REQUEST_METHOD == "POST") 
{

    /* SUBMITTED INFORMATION - use what you need
     * temporary filename (pointer): $imgfile
     * original filename           : $imgfile_name
     * size of uploaded file       : $imgfile_size
     * mime-type of uploaded file  : $imgfile_type
     */

     /*== upload directory where the file will be stored 
          relative to where script is run ==*/
    
    $uploaddir = "images";
    

    /*== get file extension (fn at bottom of script) ==*/
    /*== checks to see if image file, if not do not allow upload ==*/
    $pext = getFileExtension($imgfile_name);
    $pext = strtolower($pext);
    if (($pext != "jpg")  && ($pext != "jpeg"))
    {
        print "<h1>ERROR</h1>Image Extension Unknown.<br>";
        print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>";
        print "The file you uploaded had the following extension: $pext</p>\n";

        /*== delete uploaded file ==*/
        unlink($imgfile);
        exit();
    }


    //-- RE-SIZING UPLOADED IMAGE

    /*== only resize if the image is larger than 250 x 200 ==*/
    $imgsize = GetImageSize($imgfile);

    /*== check size  0=width, 1=height ==*/
    if (($imgsize[0] > 250) || ($imgsize[1] > 200)) 
    {
        /*== temp image file -- use "tempnam()" to generate the temp
             file name. This is done so if multiple people access the 
            script at once they won't ruin each other's temp file ==*/
        $tmpimg = tempnam("/tmp", "MKUP");

        /*== RESIZE PROCESS
             1. decompress jpeg image to pnm file (a raw image type) 
             2. scale pnm image
             3. compress pnm file to jpeg image
        ==*/
        
        /*== Step 1: djpeg decompresses jpeg to pnm ==*/
        system("djpeg $imgfile >$tmpimg");
        

        /*== Steps 2&3: scale image using pnmscale and then
             pipe into cjpeg to output jpeg file ==*/
        system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");

        /*== remove temp image ==*/
        unlink($tmpimg);

    }

    /*== setup final file location and name ==*/
    /*== change spaces to underscores in filename  ==*/
    $final_filename = str_replace(" ", "_", $imgfile_name);
    $newfile = $uploaddir . "/$final_filename";
    
    /*== do extra security check to prevent malicious abuse==*/
    if (is_uploaded_file($imgfile))
    {

       /*== move file to proper directory ==*/
       if (!copy($imgfile,"$newfile")) 
       {
          /*== if an error occurs the file could not
               be written, read or possibly does not exist ==*/
          print "Error Uploading File.";
          exit();
       }
     }

    /*== delete the temporary uploaded file ==*/
    unlink($imgfile);

    
    print("[img]\"$final_filename\"[/img]");

    /*== DO WHATEVER ELSE YOU WANT
         SUCH AS INSERT DATA INTO A DATABASE  ==*/

}
?>


</head>
<body bgcolor="#FFFFFF">

    <h2>Upload and Resize an Image</H2>

    <form action="<?=$SCRIPT_NAME; ?>" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="50000">

    <p>Upload Image: <input type="file" name="imgfile"><br>
    <font size="1">Click browse to upload a local file</font><br>
    <br>
    <input type="submit" value="Upload Image">
    </form>

</body>
</html>

<?
    /*== FUNCTIONS ==*/

    function getFileExtension($str) {

        $i = strrpos($str,".");
        if (!$i) { return ""; }

        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);

        return $ext;

    }
?>


volgensmij is het script wel goed... maar toch gaat het bij het opslaan of zo fout ? :-(

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

PHP FAQ: Mijn get/post form doet het niet meer
PHP FAQ: Mijn file-upload script werkt niet

Kijk daar eens naar. En als je geen zin hebt om het zelf uit te zoeken, dan moet je maar gewoon even de maker van het script vragen het voor je op te lossen. We doen hier niet gewoon allemaal onze code posten en maar hopen dat iemand anders het voor ons fixt, sorry.

edit:
foute linkjes fixed

[ Voor 31% gewijzigd door drm op 09-02-2004 13:43 ]

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Dit topic is gesloten.