logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 07-28-2011, 01:02 AM   #1
FethrdWlf
FethrdWlf's Avatar
 
Join Date: Jan 2011
Location: Arizona
Posts: 146
Default Error with resizing image then uploading with FTP?

So I have a script in PHP that will upload files. I've been trying to resize them, and then upload them via FTP, but I keep getting this error:
-----
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://artfulme.x10.mx/avatars/072720115418.jpg' for writing: No such file or directory in /home/artfulme/public_html/scripts/newavatar.php on line 58
-----
So I can't get it to resize the image. It uploads just fine, but the resizing... Ya' know.

Here is the newavatar.php script:
PHP Code:
<?php
    session_start
();
    include(
"mysql.php");
    
    
//Get the file's basic info.
    
$newav $_FILES['newav'];
    
$file_type $_FILES['newav']['type'];
    
$file_name $_FILES['newav']['name'];
    
$file_size $_FILES['newav']['size'];
    
$file_tmp $_FILES['newav']['tmp_name'];
    
$newpath "/public_html/avatars/";
    
$newname date("mdYis",time());
    
//Find the file extension.
    
if($file_type == "image/jpeg"){
        
$filetype ".jpg";
    }elseif(
$file_type == "image/png"){
        
$filetype ".png";
    }elseif(
$file_type == "image/gif"){
        
$filetype ".gif";
    }
    
//Check to see that the file extension is acceptable and the filesize isn't too large.
    
$size filesize($file_tmp);
    if(
$size 1048576){
        
$_SESSION['sizetoobig'] = "<p>&nbsp;&bull;&nbsp;Your avatar was over 1MB. That's too large of a file. WAY too large for <em>any</em> picture, actually. :P</p>";
    }
    if(
$file_type != "image/jpeg" && $file_type != "image/png" && $file_type != "image/gif"){
        
$_SESSION['wrongfiletype'] = "<p>&nbsp;&bull;&nbsp;The file extension of the picture you uploaded is not acceptable.</p>";
    }
    
//Create a new image from our orginal.
    
if($file_type == "image/jpeg"){
        
$src imagecreatefromjpeg($file_tmp);
    }elseif(
$file_type == "image/png"){
        
$src imagecreatefrompng($file_tmp);
    }elseif(
$file_type == "image/gif"){
        
$src imagecreatefromgif($file_tmp);
    }
    
//Find image dimensions. If the height is bigger width, then resize by height, and vice-versa.
    
list($width,$height) = getimagesize($file_tmp);
    if((
$width 80) && ($height 80)){
        
$_SESSION['toosmall'] = "<p>&nbsp;&bull;&nbsp;The image must be <em>at least</em> 80x80 pixels.</p>";
    }
    if(
$width >= $height){
        
$newwidth 80;
        
$newheight = ($height/$width)*$newwidth;
    }elseif(
$width <= $height){
        
$newheight 80;
        
$newwidth = ($width/$height)*$newheight;
    }
    
//Before doing ANYTHING, check to see if there were ANY errors. If there were, go back to the user page with an error session variable set.
    
if(($size 1048576) || (($filetype != ".jpg") && ($filetype != ".png") && ($filetype != ".gif")) || ($width $height)){
        
$_SESSION['newavatarerror'] = 1;
        
header("Location: ../user/");
    }
    
//Resize and create new image.
    
$resizedimage imagecreatetruecolor($newwidth,80);
    
imagecopyresized($resizedimage,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    if(
$filetype == ".jpg"){
        
imagejpeg($resizedimage,$newpath.$newname.$filetype,100);
    }elseif(
$filetype == ".png"){
        
imagepng($resizedimage,$newpath.$newname.$filetype,100);
    }elseif(
$filetype == ".gif"){
        
imagegif($resizedimage,$newpath.$newname.$filetype,100);
    }
    
//Upload the resized file to the server, and delete the previous one.
    
$conid ftp_connect("ftp.artfulme.x10.mx");
    
$ftplogin ftp_login($conid,"artfulme","absolutely");
    
$user $_SESSION['username'];
    
/*$nameQuery = "SELECT avatar FROM users WHERE username = '$user'";
    $nameResults = mysqli_query($cnx,$nameQuery);
    while($row = mysqli_fetch_assoc($nameResults)){
        if($row['avatar'] != "http://artfulme.x10.mx/avatars/default.png"){
            ftp_delete($conid,$row['avatar']);
        }
    } */
    
ftp_put($conid,$newpath.$newname.$filetype,$file_tmp,FTP_BINARY);
    
//Delete the temorary files that have been made and close the FTP connection.
    
imagedestroy($src);
    
imagedestroy($resizedimage);
    
ftp_close($conid);
    
//Update the users MySQL row with the new avatar link.
    
$user $_SESSION['username'];
    
$newavatarlink "http://artfulme.x10.mx/avatars/".$newname.$filetype;
    
$updateQuery "UPDATE users SET avatar = '$newavatarlink' WHERE username = '$user'";
    
$updateResults mysqli_query($cnx,$updateQuery);
    
//Go back to the user page.
?>
FethrdWlf is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:22 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com