Jump to content

klturi421

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

klturi421's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Awesome! That helps out a lot! When I put in a bad URL it returns the echo but also returns two warning messages about opening the stream. Is it possible to have it just return the echo and not the warnings? I found the following code which works well. I prefer to have everything working with no warnings unless something actually is not working right besides a bad URL. // Turn off all error reporting error_reporting(0); If not, I am comfortable with the warnings, I just prefer a prettier end result.
  2. What I am trying to achieve here is a simple URL to server file download script. It works fantastically, however, I am trying to achieve an error message when the script fails to get a file. Right now, when the file is downloaded, it provides the echo 'Successfully downloaded (FILENAME) !'. But when it fails I would like for it to say something like, file could not be downloaded. As of right now it gives me a warning that it could not open stream and it still echos file successfully downloaded. Any advice? Full code: <?php include '../dbc.php'; page_protect(); if (isset($_POST['submit'])) { $file = $_POST['filename']; $target= $_POST['hosttarget']; file_put_contents("$file", file_get_contents("$target")); echo "Successfully uploaded ".$file."!"; } else{ echo "Unable to retrieve file!"; } ?> <div class="wrap"> <FORM ENCTYPE="multipart/form-data" ACTION="" METHOD=POST> <div class="download"> <div class="left">Target:<br>Filename:</div> <div class="right"><INPUT TYPE="text" NAME="hosttarget" ID="text" VALUE=""><br> <INPUT TYPE="text" NAME="filename" ID="text" VALUE=""><br></div> <INPUT TYPE="submit" NAME="submit" ID="submit " CLASS='submit_btn' VALUE="Get File"> <div class="clear"></div> </div> </FORM> </div>
  3. I appreciate the help from everyone. With jasonc's code I was able to go a little bit further. I found on another forum that the mkdir should have @ in front Original (truncated); mkdir($name); mkdir($name); New: @mkdir($name); @mkdir($name); Once I changed the code around the warning about file exists went away. I have verified that the script uploads the image to existing folders as well as creates new folders. Again I really appreciate the help. Im not sure how to close the thread but I would say at this point my issue has been resolved.
  4. success.php <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Auto Thumbnail generation script from plus2net.com</title> </head> <body > <? if (isset($_POST['submit'])) { $name = $_POST['gname']; mkdir ("../gallery/images/$name", 0777); mkdir ("../gallery/thumbs/$name", 0777); } else{ echo "File not uploaded"; } $add="../gallery/images/$name/".$_FILES[userfile][name]; // the path with the file name where the file will be stored, upload is the directory name. //echo $add; if(move_uploaded_file ($_FILES[userfile][tmp_name],$add)){ echo "Successfully uploaded ".$_FILES[userfile][name]."<br><br>"; chmod("$add",0777); }else{echo "Failed to upload file Contact Site admin to fix the problem"; exit;} ///////// Start the thumbnail generation////////////// $n_width=100; // Fix the width of the thumb nail images $n_height=100; // Fix the height of the thumb nail imaage $tsrc="../gallery/thumbs/$name/".$_FILES[userfile][name]; // Path where thumb nail image will be stored //echo $tsrc; if (!($_FILES[userfile][type] =="image/jpeg" OR $_FILES[userfile][type]=="image/gif")){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>"; exit;} /////////////////////////////////////////////// Starting of GIF thumb nail creation/////////// if (@$_FILES[userfile][type]=="image/gif") { $im=ImageCreateFromGIF($add); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); if (function_exists("imagegif")) { Header("Content-type: image/gif"); ImageGIF($newimage,$tsrc); } elseif (function_exists("imagejpeg")) { Header("Content-type: image/jpeg"); ImageJPEG($newimage,$tsrc); } chmod("$tsrc",0777); }////////// end of gif file thumb nail creation////////// ////////////// starting of JPG thumb nail creation////////// if($_FILES[userfile][type]=="image/jpeg"){ $im=ImageCreateFromJPEG($add); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$tsrc); chmod("$tsrc",0777); } //////////////// End of JPG thumb nail creation ////////// ?> <FORM ENCTYPE="multipart/form-data" ACTION="success.php" METHOD=POST> If the directory that you would like to select is not present, type in a directory name, description and click submit. The newly created directory should appear within the list below. Otherwise, select the image and directory, click submit and you will be good to go. Name <input type="text" name="gname" id="text" value=""> Upload this file: <INPUT NAME="userfile" TYPE="file"> <INPUT TYPE="submit" name="submit" id="submit" VALUE="Send File"> </FORM> If a gallery is not available, you may create a new one. Enter then name of the Gallery in the Gallery field and upload an image. Otherwise, enter the existing gallery name into the Gallery field and upload an image.<br><br><br> List of available folders/galleries:<br> <?php function folderlist(){ $startdir = '../gallery/images/'; $ignoredDirectory[] = '.'; $ignoredDirectory[] = '..'; if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($folder = readdir($dh)) !== false){ if (!(array_search($folder,$ignoredDirectory) > -1)){ if (filetype($startdir . $folder) == "dir"){ $directorylist[$startdir . $folder]['name'] = $folder; $directorylist[$startdir . $folder]['path'] = $startdir; } } } closedir($dh); } } return($directorylist); } $folders = folderlist(); foreach ($folders as $folder){ $path = $folder['path']; $name = $folder['name']; echo '' . $name . '<br />'; } ?> </body> </html> index.php <FORM ENCTYPE="multipart/form-data" ACTION="success.php" METHOD=POST> If the directory that you would like to select is not present, type in a directory name, description and click submit. The newly created directory should appear within the list below. Otherwise, select the image and directory, click submit and you will be good to go. Name <input type="text" name="gname" id="text" value=""> Upload this file: <INPUT NAME="userfile" TYPE="file"> <INPUT TYPE="submit" name="submit" id="submit" VALUE="Send File"> </FORM> If a gallery is not available, you may create a new one. Enter then name of the Gallery in the Gallery field and upload an image. Otherwise, enter the existing gallery name into the Gallery field and upload an image.<br><br><br> List of available folders/galleries:<br> <?php function folderlist(){ $startdir = '../gallery/images/'; $ignoredDirectory[] = '.'; $ignoredDirectory[] = '..'; if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($folder = readdir($dh)) !== false){ if (!(array_search($folder,$ignoredDirectory) > -1)){ if (filetype($startdir . $folder) == "dir"){ $directorylist[$startdir . $folder]['name'] = $folder; $directorylist[$startdir . $folder]['path'] = $startdir; } } } closedir($dh); } } return($directorylist); } $folders = folderlist(); foreach ($folders as $folder){ $path = $folder['path']; $name = $folder['name']; echo '' . $name . '<br />'; } ?> It's very Frankenstein code. I found some information regarding file_exists but I haven't figured out how to write it into the code.
  5. So I have now ended up with a slightly different code. if (isset($_POST['submit'])) { $name = $_POST['gname']; mkdir ("../gallery/images/$name", 0777); mkdir ("../gallery/thumbs/$name", 0777); } else{ echo "File not uploaded"; } It works for creating the dirs, but I still get the same error as before. Essentially what I am trying to do is have a textarea where the gallery name is input, if the directory exists it just uploads the image to that directory, else it creates the directory then uploads the image. Any ideas or suggestions? I appreciate all that I have received thus far!
  6. Edit: I did it again. I corrected it this time. Even without the post line it is still returning an error. Warning: mkdir() [function.mkdir]: File exists on line 5 Warning: mkdir() [function.mkdir]: File exists on line 6
  7. It wasn't supposed to have the POST, that was an error on my part. if (!file_exists('../images/upload/upimg/$folder')) { mkdir ("../images/upload/upimg/$folder", 0777); mkdir ("../images/upload/thimg/$folder", 0777); }else { echo "Directory previously created, file uploaded successfully."; }
  8. I made the change but it is still returning the same error. if (!file_exists('../images/upload/upimg/$folder')) { $folder = $_POST['']; mkdir ("../images/upload/upimg/$folder", 0777); mkdir ("../images/upload/thimg/$folder", 0777); }else { echo "Directory previously created, file uploaded successfully."; }
  9. I have a script that will create a directory just fine but, I found a different script that I am trying to have it create a directory if necessary otherwise it will echo that the directory exists. As of right now I am just getting a 'Warning: mkdir() [function.mkdir]: File exists' My current code: if (!file_exists($folder)) { mkdir ("../images/upload/upimg/$folder", 0777); mkdir ("../images/upload/thimg/$folder", 0777); }else { echo "Directory previously created, file uploaded successfully."; } Any help would be appreciated.
  10. I have a script that will allow me to mkdir by inputing a folder name and so forth. Is there a way that I can browse for a directory or create one if needed? Is there a browse script so that I can make the dir? What I am trying to accomplish is an image upload script where I can either create a new directory or choose from an existing one. Is this even possible? Thanks in advance!
  11. Thanks Drummin, I was able to get it to work just fine with your post. I recent discovered a script from a website that will upload images and resize them and stick them in seperate folders. I have written the code and debugged it sort of. At this point each time I click upload it returns an error that says that I need to select a file even if there was a file present. The code I used: <?php //zeronese.net function create_thumbnail($source,$destination, $thumb_width) { $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $x = 0; $y = 0; if($width> $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_image = imagecreatetruecolor($thumb_width,$thumb_width) or die('Cannot Initialise new GD image stream'); $extention = get_image_extension($source); if($extension== 'jpg' || $extension=='jpeg') $image = imagecreatefromjpeg($source); if($extension== 'gif') $image = imagecreatefromgif($source); if($extension== 'png') $image = imagecreatefrompng($source); imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height); if($extension=='jpg' || $extension=='jpeg') imagejpeg($new_image,$destination); if($extension=='gif') imagegif($new_image,$destination); if($extension=='png') imagepng($new_image,$destination); } //zeronese.net //zeronese.net get_image_extension($name) function get_image_extension($name) { $name = strtolower($name); $i = strrpos($name,"."); if (!$i) { return"";} $l = strlen($name) - $i; $extension = substr($name,$i+l,$l); return $extension; }//end seronese.net get_image_extension($name) function random_name($lentgh) { $characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"; $name = ""; for ($i = 0; $i < $length; $i++) { $name .= $characters[mt_rand(0, strlen($characters) - 1)]; } return "image-".$name; } //you can change this to the directory that will hold your images $images_location = "/images/"; //this is also where we are going to store our thumbnails $thumbs_location = "/images/thumbs/"; $thumb_width = 100; //width in pixels $maximum_size = 5000000;//maximum size in kb //a message to show on our action, lets start by a help label $results = "Click browse to locate the image you want to upload!"; if($_POST){ //check if the image source is empty if($_FILES['image']['name'] == ""){ $results = "Image source can not be empty/ Please Click the 'Browse' button, locate an image then click the 'Upload Image' button!"; } //if an image source is entered, process the upload else{ $size=filesize($_FILES['image']['tmp_name']); $filename = stripslashes($_FILES['image']['name']); $extension = get_image_extension($filename); if($size > $maximum_size){ $results = "your file size exceeds the maximum size limit! Please Try Again!"; } else // allow only jpg, jpeg, gif, and png files if(($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $results = 'Images can only be with jpg,jpeg,png or gif extension. Please try again!</center>'; } else{ //generate a random name to avoid deleting duplicates $image_random_name= random_name(15).".".$extension; $copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name); if (!$copy){ $results = "Error while uploading image! Please try again!"; } else{ create_thumbnail($images_location.$image_random_name,$thumbs_location.$image_random_name, $thumb_width); $results = "Image has been uploaded"; } } } } ?> <form method="POST" enctyp="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="5000000"> <input type="file" name="image"> <input type ="submit" value="Upload Image"> </form> <?php echo $results; ?> The website where I got the code : http://www.zeronese.net/knowledge-base/questions/1060/Image-Uploading-With-Auto-Thumbnails-Using-PHP The code available on the website is not copy and pasteable, its all images. I was hoping using firebug or chrome would return some errors in console but it does nothing. EDIT: My upload page can be found at http://sophienoelle.me/uploader.php
  12. Im not sure how to do that on a GoDaddy shared server. I just tried uploading a php5.ini changing the tmp dir but havent seen any change in phpinfo yet. Am I missing something? Should I be able to access the tmp folder within the FTP client or is there another way to go about it?
  13. I have been searching for an answer for several days but have not yet resolved my problem. Essentiallty I started out looking for an image upload script then slowly went towards just a basic upload script. Each time I try a new script I am getting the same error. My folder permissions are set, file uploads is enabled, safe mode is disabled. As of right now my page is giving me an error that says 'Failed to open stream' My existing code: <?php $target = "images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> <form enctype="multipart/form-data" action="uploader.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> You for testing purposes I have made my temporary upload page available for you to view and help disgnose the issue: http://www.sophienoelle.me/uploader.php also you can find the phpinfo at http://www.sophienoelle.me/phpinfo.php If you need further information than what I have supplied please let me know and I will be available to provide what you are requesting. If you have a suggestion I will gladly take it. Any steps I can get to uploading images the better.
  14. Basically what I am trying to do is create an upload form so that I may choose what predetermined directory in a drop down to upload the file to. For example if I want to upload 'image.jpg' to the folder 'family' I can then use a drop down, select family and upload the image. So far I have yet to find a script similar to what I am trying to do. I see regular upload scripts, but nothing so that I can choose a predetermined directory. Any ideas?
×
×
  • 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.