djjjozsi;10916446 wrote:there is no images folder next to your .php file
or you did not set the 'write' permit.
if (isset ($_FILES['new_image'])){
if(!file_exists("images"))
{
mkdir("images" , "0744") or die("Could not create images folder");
die("folder created!");
}
ok i went and copied the file on my server in a subdomain. the file seems to be uploading to the website but then for some reason it doesnt get there in the end.
i made an images folder in the root and gave it full write permisions (777)
i then run the script where it was uploading the file ( could see the 5 meg traffic going through the router ) but then once again it gave me the same problem...
Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 17
Warning: Division by zero in /home/alphanig/public_html/testserver/upload-size.php on line 23
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/alphanig/public_html/testserver/upload-size.php on line 24
Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 25
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 26
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 28
Warning: getimagesize(images/_DSF8681johan.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 33
Warning: Division by zero in /home/alphanig/public_html/testserver/upload-size.php on line 39
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/alphanig/public_html/testserver/upload-size.php on line 40
Warning: imagecreatefromjpeg(images/_DSF8681johan.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/alphanig/public_html/testserver/upload-size.php on line 41
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 42
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/alphanig/public_html/testserver/upload-size.php on line 44
Large image: ( again a broken link )
Thumbnail: ( again a broken link )
the file is in my root of the test domain and also is the folder.
http://testserver.alphanightlife.co.za/upload-size.php
http://testserver.alphanightlife.co.za/images/
and this is the code now...
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
<button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
if(isset($_POST['submit'])){
if (isset ($_FILES['new_image'])){
if(!file_exists("images"))
{
mkdir("images" , "0744") or die("Could not create images folder");
die("folder created!");
}
$imagename = basename($_FILES['new_image']['name']);
$source = $_FILES['new_image']['tmp_name'];
$target = "images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "images/" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 150;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "images/sml_" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 80;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
echo "Large image: <img src='images/".$imagepath."'><br>";
echo "Thumbnail: <img src='images/sml_".$imagepath."'>";
}
}
?>