Storing temporary files in a different location
Posted: Fri Apr 14, 2006 3:31 pm
I'm using the following PHP script from one of your tutorials to get a file from a form:
Now, when I use the script on my page, I get the following errors:
Thanks much!
Code: Select all
<?php
// Get the details of "imagefile"
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];
//Open the image using the imagecreatefrom..() command based on the MIME type.
switch($mimetype) {
case "image/jpg":
case "image/jpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
case "image/png":
$i = imagecreatefrompng($temporary_name);
break;
}
//Delete the uploaded file
unlink($temporary_name);
//Save a copy of the original
imagejpeg($i,"images/uploadedfile.jpg",90);
//Specify the size of the thumbnail
$dest_x = 150;
$dest_y = 150;
//Is the original bigger than the thumbnail dimensions?
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
//Is the width of the original bigger than the height?
if (imagesx($i) >= imagesy($i)) {
$thumb_x = $dest_x;
$thumb_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$thumb_x = imagesx($i)*($dest_y/imagesy($i));
$thumb_y = $dest_y;
}
} else {
//Using the original dimensions
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}
//Generate a new image at the size of the thumbnail
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);
//Copy the original image data to it using resampling
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
//Save the thumbnail
imagejpeg($thumb, "images/thumbnail.jpg", 80);
?>I assume that means that I'm not allowed to store the temporary files in the location they are trying to be stored because of a restriction my webhost put on. Is there any way I can change the location where the temp file are stored without editing the php.ini file?Warning: imagecreatefrompng(): open_basedir restriction in effect. File(/var/tmp/phpYVFlOh) is not within the allowed path(s): (/home/epicart2/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/epicart2/public_html/thunderstorms/formupload.php on line 40
Warning: imagecreatefrompng(/var/tmp/phpYVFlOh): failed to open stream: Operation not permitted in /home/epicart2/public_html/thunderstorms/formupload.php on line 40
Warning: unlink(): open_basedir restriction in effect. File(/var/tmp/phpYVFlOh) is not within the allowed path(s): (/home/epicart2/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/epicart2/public_html/thunderstorms/formupload.php on line 46
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 49
Warning: imagesx(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 55
Warning: imagesy(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 55
Warning: imagesx(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 73
Warning: imagesy(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 74
Warning: imagecreatetruecolor(): Invalid image dimensions in /home/epicart2/public_html/thunderstorms/formupload.php on line 78
Warning: imagesx(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 81
Warning: imagesy(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 81
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 81
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/epicart2/public_html/thunderstorms/formupload.php on line 85
Thanks much!