Jump to content

bobdole

Members
  • Posts

    12
  • Joined

  • Last visited

bobdole's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was able to get it working. Thank you though. I simply didn't understand I didn't need to use a FTP to upload a file. Here was my code if anyone is curious: html form - onsubmit run "image_upload_script.php" <!-- -------------------------------------------- --> <!-- "image_upload_script.php" --> <!-- -------------------------------------------- --> <?php // Access the $_FILES global variable for this specific file being uploaded // and create local PHP variables from the $_FILES array of information $fileName = $_FILES["uploaded_file"]["name"]; // The file name $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is $fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 for false... and 1 for true $kaboom = explode(".", $fileName); // Split file name into an array using the dot $fileExt = end($kaboom); // Now target the last array element to get the file extension // START PHP Image Upload Error Handling -------------------------------------------------- if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes echo "ERROR: Your file was larger than 5 Megabytes in size."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) { // This condition is only if you wish to allow uploading of specific file types echo "ERROR: Your image was not .gif, .jpg, or .png."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1 echo "ERROR: An error occured while processing the file. Try again."; exit(); } // END PHP Image Upload Error Handling ---------------------------------------------------- // Place it into your "uploads" folder mow using the move_uploaded_file() function $moveResult = move_uploaded_file($fileTmpLoc, "memes/$fileName"); // Check to make sure the move result is true before continuing if ($moveResult != true) { echo "ERROR: File not uploaded. Try again."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } //unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder // ---------- Include Adams Universal Image Resizing Function -------- include_once("ak_php_img_lib_1.0.php"); $target_file = "memes/$fileName"; $resized_file = "memes/$fileName"; $wmax = 500; $hmax = 1000; ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt); // ----------- End Adams Universal Image Resizing Function ----------- // Display things to the page so you can see what is happening for testing purposes echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />"; echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />"; echo "It is an <strong>$fileType</strong> type of file.<br /><br />"; echo "The file extension is <strong>$fileExt</strong><br /><br />"; echo "The Error Message output for this upload is: $fileErrorMsg"; ?> <!-- -------------------------------------------- --> <!-- "ak_php_img_lib_1.0.php" --> <!-- -------------------------------------------- --> <?php // Adam Khoury PHP Image Function Library 1.0 // ----------------------- RESIZE FUNCTION ----------------------- // Function for resizing any jpg, gif, or png image files function ak_img_resize($target, $newcopy, $w, $h, $ext) { list($w_orig, $h_orig) = getimagesize($target); $scale_ratio = $w_orig / $h_orig; if (($w / $h) > $scale_ratio) { $w = $h * $scale_ratio; } else { $h = $w / $scale_ratio; } $img = ""; $ext = strtolower($ext); if ($ext == "gif"){ $img = imagecreatefromgif($target); } else if($ext =="png"){ $img = imagecreatefrompng($target); } else { $img = imagecreatefromjpeg($target); } $tci = imagecreatetruecolor($w, $h); // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h) imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig); if ($ext == "gif"){ imagegif($tci, $newcopy); } else if($ext =="png"){ imagepng($tci, $newcopy); } else { imagejpeg($tci, $newcopy, 84); } } // -------------- THUMBNAIL (CROP) FUNCTION --------------- // Function for creating a true thumbnail cropping from any jpg, gif, or png image files function ak_img_thumb($target, $newcopy, $w, $h, $ext) { list($w_orig, $h_orig) = getimagesize($target); $src_x = ($w_orig / 2) - ($w / 2); $src_y = ($h_orig / 2) - ($h / 2); $ext = strtolower($ext); $img = ""; if ($ext == "gif"){ $img = imagecreatefromgif($target); } else if($ext =="png"){ $img = imagecreatefrompng($target); } else { $img = imagecreatefromjpeg($target); } $tci = imagecreatetruecolor($w, $h); imagecopyresampled($tci, $img, 0, 0, $src_x, $src_y, $w, $h, $w, $h); if ($ext == "gif"){ imagegif($tci, $newcopy); } else if($ext =="png"){ imagepng($tci, $newcopy); } else { imagejpeg($tci, $newcopy, 84); } } // ----------------------- IMAGE WATERMARK FUNCTION ----------------------- // Function for applying a PNG watermark file to a file after you convert the upload to JPG function ak_img_watermark($target, $wtrmrk_file, $newcopy) { $watermark = imagecreatefrompng($wtrmrk_file); imagealphablending($watermark, false); imagesavealpha($watermark, true); $img = imagecreatefromjpeg($target); $img_w = imagesx($img); $img_h = imagesy($img); $wtrmrk_w = imagesx($watermark); $wtrmrk_h = imagesy($watermark); $dst_x = ($img_w / 2) - ($wtrmrk_w / 2); // For centering the watermark on any image $dst_y = ($img_h / 2) - ($wtrmrk_h / 2); // For centering the watermark on any image imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h); imagejpeg($img, $newcopy, 100); imagedestroy($img); imagedestroy($watermark); } ?>
  2. Alright, the quality was not the problem, but it was a great guess. I'm trying this script now. It works but the image shows up next to each other left to right instead of below the first image. <?php merge('image1.jpg', 'image2.jpg', 'uploads/merged.jpg'); function merge($filename_x, $filename_y, $filename_result) { // Get dimensions for specified images list($width_x, $height_x) = getimagesize($filename_x); list($width_y, $height_y) = getimagesize($filename_y); // Create new image with desired dimensions $image = imagecreatetruecolor($width_x + $width_y, $height_x); // Load images and then copy to destination image $image_x = imagecreatefromjpeg($filename_x); $image_y = imagecreatefromjpeg($filename_y); imagecopy($image, $image_x, 0, 0, 0, 0, $width_x, $height_x); imagecopy($image, $image_y, $width_x, 0, 0, 0, $width_y, $height_y); // Save the resulting image to disk (as JPEG) imagejpeg($image, $filename_result); // Clean up imagedestroy($image); imagedestroy($image_x); imagedestroy($image_y); } ?> Any slight modifications to get this to work?
  3. That's probably it! Thanks, I'm trying it out and trying to learn to use that function correctly. Although that might not be directly it. It changes the image to horrible quality where it is incredibly blurry and an entirely different color. I;m not sure if the difference between 100% and 75% would do that.
  4. I'm using a simple script for Image Copy. It's adding an image to the bottom of another image. Both images are the same width. The script works fine, but it changes the color of my images and makes it blurry??? I have no clue why, can anyone help me out
  5. I keep getting the error: This is the same no matter how many generic watermark scripts I use. So the question is... Where am I supposed to have my watermark.png located? Is it supposed to be on mydomain.com/watermark.png or what? Here is the code: <html> <head> </head> <body> <form action="watermark-image.php" method="post" enctype="multipart/form-data"> Select a file to upload for processing<br> <input type="file" name="File1"><br> <input type="submit" value="Submit File"> </form> </body> </html> <?php /* * PHP function to image-watermark an image * http://salman-w.blogspot.com/2008/11/watermark-your-images-with-another.html * * Writes the given watermark image on the specified image * and saves the result as another image */ define('WATERMARK_OVERLAY_IMAGE', 'watermark.png'); define('WATERMARK_OVERLAY_OPACITY', 50); define('WATERMARK_OUTPUT_QUALITY', 90); function create_watermark($source_file_path, $output_file_path) { list($source_width, $source_height, $source_type) = getimagesize($source_file_path); if ($source_type === NULL) { return false; } switch ($source_type) { case IMAGETYPE_GIF: $source_gd_image = imagecreatefromgif($source_file_path); break; case IMAGETYPE_JPEG: $source_gd_image = imagecreatefromjpeg($source_file_path); break; case IMAGETYPE_PNG: $source_gd_image = imagecreatefrompng($source_file_path); break; default: return false; } $overlay_gd_image = imagecreatefrompng(WATERMARK_OVERLAY_IMAGE); $overlay_width = imagesx($overlay_gd_image); $overlay_height = imagesy($overlay_gd_image); imagecopymerge( $source_gd_image, $overlay_gd_image, $source_width - $overlay_width, $source_height - $overlay_height, 0, 0, $overlay_width, $overlay_height, WATERMARK_OVERLAY_OPACITY ); imagejpeg($source_gd_image, $output_file_path, WATERMARK_OUTPUT_QUALITY); imagedestroy($source_gd_image); imagedestroy($overlay_gd_image); } /* * Uploaded file processing function */ define('UPLOADED_IMAGE_DESTINATION', 'uploads/'); define('PROCESSED_IMAGE_DESTINATION', 'images/'); function process_image_upload($Field) { $temp_file_path = $_FILES[$Field]['tmp_name']; $temp_file_name = $_FILES[$Field]['name']; list(, , $temp_type) = getimagesize($temp_file_path); if ($temp_type === NULL) { return false; } switch ($temp_type) { case IMAGETYPE_GIF: break; case IMAGETYPE_JPEG: break; case IMAGETYPE_PNG: break; default: return false; } $uploaded_file_path = UPLOADED_IMAGE_DESTINATION . $temp_file_name; $processed_file_path = PROCESSED_IMAGE_DESTINATION . preg_replace('/\\.[^\\.]+$/', '.jpg', $temp_file_name); move_uploaded_file($temp_file_path, $uploaded_file_path); $result = create_watermark($uploaded_file_path, $processed_file_path); if ($result === false) { return false; } else { return array($uploaded_file_path, $processed_file_path); } } /* * Here is how to call the function(s) */ $result = process_image_upload('File1'); if ($result === false) { echo '<br>An error occurred during file processing.'; } else { echo '<br>Original image saved as <a href="' . $result[0] . '" target="_blank">' . $result[0] . '</a>'; echo '<br>Watermarked image saved as <a href="' . $result[1] . '" target="_blank">' . $result[1] . '</a>'; } ?>
  6. So it's looking like I don't even need to use my ftp account. Awesome. Most people don't like to many details, but I see you are not one of them. I was just worried I would scare people off and cause them not to answer with a length post. So here is my code now: <html> <head> </head> <body> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> </body> </html> This code links to "uploader.php" which is here: <?php // Example of accessing data for a newly uploaded file $fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // Path and file name $pathAndName = "images/".$fileName; // Run the move_uploaded_file() function here $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); // Evaluate the value returned from the function if needed if ($moveResult == true) { echo "File has been moved from " . $fileTmpLoc . " to" . $pathAndName; } else { echo "ERROR: File not moved correctly"; } ?> I am trying to use a file chooser to grab the image name. I keep getting: ERROR: File not moved correctly Any help would be awesome! I'm so close.
  7. Thanks for the replies. @teynonThanks for the help, and that link seems like a useful program. Although it seems a little to big for the simple program I am trying to implement. @cpd I'm not communicating very clearly, so I will be more precise with my comments. I actually don't have many errors. What I should have said was I have questions and not errors. I'm not sure how to approach the situation is what I am trying to say. I'll explain what I am trying to do: I have an html form where I upload a file and it does unrelated stuff to my website on submit. I am only uploading pictures. I was hoping to add another function that also puts the image I just submited online on my site. The directory is "mysite/images/" I get a broken image when I try to look at the image, so I have to go into my filezilla and upload the image manually. Everything works then, but the problem is I upload many images at a time and I wish to make things quicker.
  8. This site was very useful, I tried out the entire tutorial. I am not sure I understand though. To upload a file to my server, I don't even need my FTP login or password? Is that correct? Yes, that is what I am trying to do. Using php, I want to upload a few images to my server in the directory "code-crash.com/uploads" or "root/uploads' I am still getting many errors though :/
  9. Hey guys, I've searched this and couldn't find a way to do it that works. I'm looking for a form, that has a file upload button and a submit button. Once the user clicks submit, the selected file gets uploaded on the users ftp. I'm using godaddy as my hosting. Does anyone know how to approach this?
  10. The domain name seems to load a lot longer before giving me an error unlike the ip address. Perhaps I am just putting in the domain incorrectly?
  11. Thanks, yes that is a good step in the right direction. I keep getting "Couldn't connect to ..." I have tried the IP address and the domain name. Which does you guys usually use?? Godaddy (which I use) might be different. I am trying it with either $ftp_server = "www.code-crash.com"; or $ftp_server = "184.168.25.1"; Aren't these pretty standard?
  12. Hi there. I love your forum and have been really into php lately, so I thought I would get involved. I do have a question though. I have been using Filezilla as my ftp and it has been working greatly with the following info: User: code2288 Password: mypass (Obviously different) Host: 184.168.25.1 I get his error when I try it in my php code: Here is my code if anyone can help me <html> <head> </head> <body> <?php // variables $ftp_server = "184.168.25.1"; //$ftp_server = "www.code-crash.com"; $ftp_user_name = "code2288"; $ftp_user_pass = "Texascrash3!"; $destination_file = "images/catalogue/".$_FILES['image']['name']; $sourcefile = $_FILES['image']['name']; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name"; } // upload the file $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); // line 30 // check upload status if (!$upload) { echo "FTP upload has failed!"; } else { echo "Uploaded $source_file to $ftp_server as $destination_file"; } // close the FTP stream ftp_close($conn_id); ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.