paddymull Posted March 29, 2008 Share Posted March 29, 2008 Hi all am using php4 image uploader found here http://www.kreoton.net/php-image-upload-script but i cant manage to send the image uploads to a different directory. for example lets say i have the php4 script hosted at www.members.mysite.com/ but i want all images to be uploaded to wwww.mysite.com/uploads/ how can i do this??? Can this be done???? I changed the $upload_dir in config.php to http://wwww.mysite.com/uploads/ but i get the following error Warning: move_uploaded_file(http://wwww.mysite.com/uploads/bde26347791a853e1aed6275518aa1b1.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections. in /home/fhlinux152/m/members.mysite.com/user/htdocs/php4upload.class.php on line 77 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpT7cyPW' to 'http://wwww.mysite.com/uploads/bde26347791a853e1aed6275518aa1b1.jpg' in /home/fhlinux152/m/members.mysite.com/user/htdocs/php4upload.class.php on line 77 does anyone now how i can fix this so i can upload the images to a different domain. thanks from Patrick below is the files included in script index.php <?php require 'php4upload.class.php'; require 'config.php'; $im = new imageupload(); if ($_POST['__upload']) { header('location: '.'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF'])); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html> <head> <title><?=$title?></title> <style type="text/css"> body { margin:0; font-family:Verdana, arial, sans-serif; font-size:12px; } div.wrapper { margin:0 auto; padding:5px; width:620px; border:1px solid #35528F; } h1 { padding:8px; margin:0px; } div.errors { color:#FF0000; } ul { list-style:none; padding:5px; } ul li { display:inline; padding-right:12px; } p.footer { clear:both; text-align:center; font-size:10px; } div.block { float:left; width:300px; } div.errors { color:red; } </style> </head> <body> <div class="wrapper"> <h1><?=$title?></h1> <ul> <li><a href="/">Home</a></li> <li><a href="http://www.kreoton.net/">Visit</a></li> </ul> <p>Browse file to upload</p> <form method="post" enctype="multipart/form-data" action="<?=$im->path?>"> <input type="file" name="__upload" size="72" /> <input type="submit" value="Upload" /> </form> <p><?=$im->allowTypes();?></p> <div class="block"> <? if ($im->_im_status == true) { echo '<h2>Upload Successful!</h2> <p class="codes"><label for="codebb">Embed on bulletin boards:</label><br /> <input type="text" size="40" value="" onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codehtml">Embed on webpages or MySpace: </label><br /> <input type="text" size="40" value=\'<a href="'.$im->imgurl.'"><img src="'.$im->imgurl.'" alt="Image hosting by '.$title.'" /></a>\' onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codedirect">Direct link:</label><br /> <input type="text" size="40" value="'.$im->imgurl.'" onclick="javascript:this.focus();this.select();" readonly="true" /></p>'; } elseif (!empty($im->errorStr)) { echo '<div class="errors">'.$im->errorStr.'</div>'; } else { echo ' <script type="text/javascript"><!-- google_ad_client = "pub-1893529756907581"; google_ad_width = 300; google_ad_height = 250; google_ad_format = "300x250_as"; google_ad_type = "text_image"; google_ad_channel = ""; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } ?> </div> <div class="block"> <script type="text/javascript"><!-- google_ad_client = "pub-1893529756907581"; google_ad_width = 300; google_ad_height = 250; google_ad_format = "300x250_as"; google_ad_type = "text_image"; google_ad_channel = ""; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <p class="footer">Powered By <a href="http://www.kreoton.net/">PHP Image Upload</a></p> </div> </body> </html> config.php <?php /* - PHP4 Image upload script - coded by kreoton - downloaded from www.kreoton.net */ $title = 'PHP4 Image Upload'; $types = array('jpg', 'gif', 'png'); $maxsize = 1024*1024; $upload_dir = 'uploads/'; //language $lang['E_TYPE'] = 'Wrong image type.'; $lang['E_SIZE'] = 'File seze is not acceptable.'; ?> phpupload.class.php <?php /* - PHP4 Image upload script - coded by kreoton - downloaded from www.kreoton.net */ class imageupload { //pblic variables var $path = ''; var $errorStr = ''; var $imgurl = ''; //private variables var $_errors = array(); var $_params = array(); var $_lang = array(); var $_maxsize = 1048576; var $_im_status = false; //public methods function imageupload () { require 'config.php'; $this->_types = $types; $this->_lang = $lang; $this->_upload_dir = $upload_dir; $this->_maxsize = $maxsize; $this->path = $PHP_SELF; if (is_array($_FILES['__upload'])) { $this->_params = $_FILES['__upload']; if (function_exists('exif_imagetype')) $this->_doSafeUpload(); else $this->_doUpload(); if (count($this->_errors) > 0) $this->_errorMsg(); } } function allowTypes () { $str = ''; if (count($this->_types) > 0) { $str = 'Allowed types: ('; $str .= implode(', ', $this->_types); $str .= ')'; } return $str; } // private methods function _doSafeUpload () { preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); if (exif_imagetype($this->_params['tmp_name']) && in_array(strtolower($matches[1]), $this->_types)) { if ($this->_params['size'] > $this->_maxsize) $this->_errors[] = $this->_lang['E_SIZE']; else $this->_im_status = true; if ($this->_im_status == true) { $ext = substr($this->_params['name'], -4); $this->new_name = md5(time()).$ext; move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.$this->new_name; } } else $this->_errors[] = $this->_lang['E_TYPE']; } function _doUpload () { preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); if(in_array(strtolower($matches[1]), $this->_types)) { if ($this->_params['size'] > $this->_maxsize) $this->_errors[] = $this->_lang['E_SIZE']; else $this->_im_status = true; if ($this->_im_status == true) { $ext = substr($this->_params['name'], -3); $this->new_name = md5(time()).$ext; move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name; } } else $this->_errors[] = $this->_lang['E_TYPE']; } function _errorMsg() { $this->errorStr = implode('<br />', $this->_errors); } } ?> please help thanks from patrick Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/ Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 I changed the $upload_dir in config.php to http://wwww.mysite.com/uploads/ but i get the following error as you now know.. that won't work.. you need to use the file path not the web path So if the imageupload.php file is on the top level and then you have a folder called uploads ie http://wwww.mysite.com/uploads/imageupload.php <-- php file http://wwww.mysite.com/uploads/ <--put uploads here change $upload_dir to $upload_dir = dirname(__FILE__)."/uploads/" Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503716 Share on other sites More sharing options...
paddymull Posted March 29, 2008 Author Share Posted March 29, 2008 the thing is that file is going to be in a password protected area so i need the images to be hosted in a folder that isn't password protected so the images uploaded can be seen by everyone and not just members. but i only want members to be able to upload them. i was thinking to have the image folder lets say www.mysite.com/uploads and the upload script www.mysite.com/member1/ so the member1 folder will be password protected but the uploads folder wont be so the images can be seen. i tried putting ../uploads next to $upload_dir in the config but this didn't work can anyone help me and let me know how to do this thanks Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503733 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 try $upload_dir = dirname(__FILE__)."/../uploads/" dirname(__FILE__) = works out the folder the PHP file in Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503735 Share on other sites More sharing options...
paddymull Posted March 29, 2008 Author Share Posted March 29, 2008 No i get the following erorr message Warning: move_uploaded_file(/home/fhlinux152/m/pmb-web-designs.co.uk/user/htdocs/1/manager/../uploads/08cc4d51e8cc2ce279346aeb9f8bc825.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/fhlinux152/m/pmb-web-designs.co.uk/user/htdocs/1/manager/php4upload.class.php on line 77 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIGnDuJ' to '/home/fhlinux152/m/pmb-web-designs.co.uk/user/htdocs/1/manager/../uploads/08cc4d51e8cc2ce279346aeb9f8bc825.jpg' in /home/fhlinux152/m/pmb-web-designs.co.uk/user/htdocs/1/manager/php4upload.class.php on line 77 Its looks like its just adding the ../uploads to the link. the php file is in the pmb-web-designs.co.uk/1/manger/ and i want to sent the images to pmb-web-designs.co.uk/uploads/ ???????????????????? am stuck lol Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503743 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 can you post your directory structor.. as a guess you have a this 1/manager/imageupload.php then i assume you have upload/ <-- you want them here if so you need to go back twice $upload_dir = dirname(__FILE__)."/../../uploads/" Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503746 Share on other sites More sharing options...
paddymull Posted March 29, 2008 Author Share Posted March 29, 2008 can you post your directory structor.. as a guess you have a this 1/manager/imageupload.php then i assume you have upload/ <-- you want them here if so you need to go back twice $upload_dir = dirname(__FILE__)."/../../uploads/" your right with the directory structor no that doesnt work it just adds on the the link it gives ot the link http://pmb-web-designs.co.uk/1/manager//home/fhlinux152/m/pmb-web-designs.co.uk/user/htdocs/1/manager/../../uploads/441edddb577f5ab1f6147de2d54f2df9.jpg Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503754 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 erm.. how could the link include the URL ? anyways the last one should of worked.. did you get the same error ? Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503758 Share on other sites More sharing options...
paddymull Posted March 29, 2008 Author Share Posted March 29, 2008 Just checked the folder and the image was uploaded is just not showing the correct link on the page, it should upload the image then display the link. but the link is showing up incorrect, i will look at the code now see if i can fix it. Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503763 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 try changinh $upload_dir = dirname(__FILE__)."/../../uploads/"; to $upload_dir = "/../../uploads/"; and move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name; to move_uploaded_file($this->_params['tmp_name'], dirname(__FILE__).$this->_upload_dir.$this->new_name); $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name; Quote Link to comment https://forums.phpfreaks.com/topic/98430-php-image-upload-help/#findComment-503783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.