PHP - Image Path Question
How can I make the image path not have the starting slash for the $path?
Currently this... Code: [Select] function getUserAvatar($username) { if (file_exists("{$GLOBALS['path']}/img/${username}.png")) { return "/assets/img/${username}.png"; } else { return "/assets/img/defaultuser.jpg"; } } When path is executed I need it to make /assets/ be assets/ I need to remove the first character from the $path variable. if ($type === 'image/png'){ imagepng($this->img, $path); } Similar TutorialsHi! So I'm working for someone, and they want me to fix this error in a PHP file.. Here is the code: <?php include_once('config.php'); $online = mysql_query("SELECT * FROM bots WHERE status LIKE 'Online'"); $offline = mysql_query("SELECT * FROM bots WHERE status LIKE 'Offline'"); $dead = mysql_query("SELECT * FROM bots WHERE status LIKE 'Dead'"); $admintrue = mysql_query("SELECT * FROM bots WHERE admin LIKE 'True'"); $adminfalse = mysql_query("SELECT * FROM bots WHERE admin LIKE 'False'"); $windows8 = mysql_query("SELECT * FROM bots WHERE so LIKE '%8%'"); $windows7 = mysql_query("SELECT * FROM bots WHERE so LIKE '%7%'"); $windowsvista = mysql_query("SELECT * FROM bots WHERE so LIKE '%vista%'"); $windowsxp = mysql_query("SELECT * FROM bots WHERE so LIKE '%xp%'"); $unknown = mysql_query("SELECT * FROM bots WHERE so LIKE 'Unknown'"); $totalbots = mysql_num_rows(mysql_query("SELECT * FROM bots")); $onlinecount = 0; $offlinecount = 0; $deadcount = 0; $admintruecount = 0; $adminfalsecount = 0; $windows8count = 0; $windows7count = 0; $windowsvistacount = 0; $windowsxpcount = 0; $unknowncount = 0; while($row = mysql_fetch_array($online)){ $onlinecount++; } while($row = mysql_fetch_array($offline)){ $offlinecount++; } while($row = mysql_fetch_array($dead)){ $deadcount++; } while($row = mysql_fetch_array($admintrue)){ $admintruecount++; } while($row = mysql_fetch_array($adminfalse)){ $adminfalsecount++; } while($row = mysql_fetch_array($windows8)){ $windows8count++; } while($row = mysql_fetch_array($windows7)){ $windows7count++; } while($row = mysql_fetch_array($windowsvista)){ $windowsvistacount++; } while($row = mysql_fetch_array($windowsxp)){ $windowsxpcount++; } while($row = mysql_fetch_array($unknown)){ $unknowncount++; } $statustotal = $onlinecount + $offlinecount + $deadcount; $admintotal = $admintruecount + $adminfalsecount; $sototal = $windows7count + $windowsvistacount + $windowsxpcount + $unknowncount; ?> Can anyone tell me the error here, can how to fix it? This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=351137.0 Hey Everyone, I have these 3 scripts to upload an image but I'm having an issue because the images uploaded are going to the same directory as the pages. What do I need to change to make the uploaded images go to a folder path called "pictures". Thanks in advance for the help. Script 1 <form name="form1" method="post" action="adminpicturebrowse.php"> <p align="center">How many pictures for this dog? Max is 9</p> <p align="center"> <input name="uploadNeed" type="text" id="uploadNeed" maxlength="1"> <input type="submit" name="Submit" value="Submit"> </p> </form> Script 2 <form name="form1" enctype="multipart/form-data" method="post" action="adminaddupload.php"> <p align="center"> <? // start of dynamic form $uploadNeed = $_POST['uploadNeed']; for($x=0;$x<$uploadNeed;$x++){ ?> <input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>"> </p> <div align="center"> <? // end of for loop } ?> </div> <p align="center"><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>"> <input type="submit" name="Submit" value="Submit"> </p> </form> Script 3 <? $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name); // check if successfully copied if($copy){ echo "$file_name<br>"; }else{ echo "$file_name<br>"; } } // end of loop ?> Hi, How can i show image using absolute path instead of virtual path?? Help please I have the folder structure like:
root
application
system
assets
uploads
folder assets contains all css, img, and js.
uploads contains user uploaded file.
I set a "helper/assets_helper.php" file to define:
define ('ASSETS_PATH', base_url().'assets/'); define ('UPLOAD_URL', base_url().'uploads/');For all the css, img, and js, it works well like href="<?php echo ASSETS_PATH; ?>css/mycss.css"But when I display the uploaded images, it couldn't display image with <a href="<?php echo UPLOAD_URL;?>images/myupload01.jpg" ><img src="<?php echo UPLOAD_URL;?>images/myupload01.jpg" /></a>This uploaded image actually works fine with my localhost with the link like: http://localhost:900.../myupload01.jpg. But it couldn't display on my hosting server with like: http://users.mywebsi.../myupload01.jpg Can anyone shed some light on it. Thanks! Edited by TFT2012, 20 October 2014 - 10:43 AM. hi i want to store url to images in database for logged in users (where id = $id) and recall the image hopefully using --------------------- <img src="<?php echo row['link']; ?>" /> or similar and need help with the sql update string any ideas please help i been stuck with this for some time and now decided to ask around in this forum for help, please help if you can. So, I am your typical newbie to php. I am usually doing more design stuff, but now I am diving into PHP. The script in question is made for a user to upload an image to a respective directory. Also the path, category, and 2 tags representing the image will be uploaded to a mySQL database. My problem is that I have pieced together some freeware scripts that I have found in order to accomplish my ultimate goal. I need the form to be processed on the same page, because I don't want to redirect users. I also need to upload the respective information to the database. Right now, when you upload an image it only seems to be processing a part of the form, and does not upload any of the information at all. Can someone spot the many things that I am doing wrong and provide me with some direction? I have two files in question image_upload.php (Sorry about all of the code) <?php require_once 'upload_config.php'; function VerifyForm(&$values, &$errors) { // Do all necessary form verification if($clear_folder_before_upload){ $mydirectory = myUploadDir(); EmptyDir($mydirectory); } $uploaded_file_counter=0; $UploadLimit = $_POST['counter']; for($i=0;$i<=$UploadLimit;$i++){ $file_tag='filename'.$i; $filename=$_FILES[$file_tag]['name']; if($filename!=null) { $rand=time(); $str="$rand$filename"; // set folder name in here. $filedir= myUploadDir(); //change the string format. $string= $filedir.$str; $patterns[0] = "/ /"; $patterns[1] = "/ /"; $patterns[1] = "/ /"; $replacements[1] = "_"; $dirname=strtolower(preg_replace($patterns, $replacements, $string)); //end of changing string format //checking the permitted file types if($check_file_extentions) { $allowedExtensions = allowedfiles(); foreach ($_FILES as $file) { if ($file['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { $fileUploadPermission=0; } else { $fileUploadPermission=1; } } } } else{ $fileUploadPermission=1; } //end of checking the permitted file types if($fileUploadPermission){ if(move_uploaded_file($_FILES[$file_tag]['tmp_name'],$dirname)) { echo "<img src='$dirname'>"; $uploaded_file_counter+=1; } } } } if($uploaded_file_counter==0){ echo "<br /> <b style='font-weight:bold;color:red'>Oops! Please select an image file</b>"; }else{ echo "<br /> <b>You requested ".$i." image files to upload and ".$uploaded_file_counter." files uploaded sucessfully</b>"; echo $filename0; $contentdiv = 'Upload succesful! Upload Again'; } } function DisplayForm($values, $errors) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JayGilford.com :: Name form example</title> <script type="text/javascript" src="js/jquery-1.4.2.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script> <style type="text/css"> div#upload_box_wrapper{width:350px;text-align:center; float: left;font-family: verdana; font-size: 12px;padding: 5px 5px 5px 5px; color: black;} div#upload_box_wrapper #upload_title_text{text-align:left;width: 100%;display: block;border: 0px solid green; margin-bottom: 5px;} div#upload_box_wrapper #FileUploadDiv{display: block;width: 98%;border: 0px solid green; text-align: left;padding: 0px 0px 0px 0px;} div#upload_box_wrapper p.add-new-upload-box{float: left;width: 100%;text-align: left;} div#upload_box_wrapper a.add-new-upload-link{font-weight: bold;font-size: 13px;padding-right: 3px;text-decoration: none; color: black;} div#upload_box_wrapper .upload-button{border: 0px solid lightgreen;height:30px; width:120px;cursor: pointer;background:url(./images/upload_button.png) no-repeat center left; color: white;} </style> </head> <body> <form method='post' action='' enctype='multipart/form-data'> <div id="upload_box_wrapper"> <div id="upload_title_text">Image Upload:</div> <div id="FileUploadDiv" DivValue="0"> <input name='filename0' type='file' id='filename'> <select name="img_category"> <option value="Vacation">Vacation</option> <option value="Holiday">Holiday</option> </select> <input name="tag1" type="text" id="tag1"> <input name="tag2" type="text" id="tag2"> </div> <input type="hidden" value="0" id="counter" name="counter"> <div align='left'> <input type='submit' name='submit' value='Upload Now!' class="upload-button"> </div> </div> </form> </body> </html> <?php } function ProcessForm($values) { $filename0 = $_POST['filename']; $filetype = $_POST['']; $img_category = $_POST['img_category']; $tag1 = $_POST['tag1']; $tag2 = $_POST['tag2']; //////// //figure out the image?? ///// session_start(); $img = $_POST[ 'imglink' ]; $filetypes = array( 'gif','jpg','jpeg','png' ); ++$filetypes; $filetype = strstr( $img, '.' ); if( $filetype != $filetypes ) { echo 'not supported'; } session_register( 'Image' ); $Img = $_SESSION[ 'Image' ]; mysql_query( "INSERT into `images` ( `image_id`, `filename`, `filetype`, `url`, `img_category`, `tag1`, `tag2` ) VALUES ( '', '$filename0', '$filetype', '$Img', '$img_category', '$tag1', '$tag2' )" ); session_destroy(); mysql_close( $DB ); // Replace with actual page or redirect :P } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); if (!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> and the upload_config.php file <?php /////////////////////////////////////////////////////////////////////////// //establish mysql connection (I have this set correctly on the original file) /////////////////////////////////////////////////////////////////////////// $db = mysql_connect('RESPECTIVE', 'MYSQL', IDANDPW'); if (!$db) { echo "Unable to establish connection to database server"; exit; } if (!mysql_select_db('chad_images', $db)) { echo "Unable to connect to database"; exit; } /////////////////////////////////////////////////////////////////////////// // set your upload directory name in here. /////////////////////////////////////////////////////////////////////////// function myUploadDir(){ $myUploadDir = "./upload/"; return $myUploadDir; } /////////////////////////////////////////////////////////////////////////// // if you want to imposs file type rescriction then // $check_file_extentions=1 or if you want to off this option then // $check_file_extentions=0 /////////////////////////////////////////////////////////////////////////// $check_file_extentions = 1; //////////////////////////////////////////////////////////////////////////// // set your allowed type in the array. // examples: zip, pdf, psd and many more. // //////////////////////////////////////////////////////////////////////////// function allowedfiles() { $allowed_file_extensions=array("png","jpg","gif","bmp"); return $allowed_file_extensions; } /////////////////////////////////////////////////////////////////////////// // if you want to delete all the files in uploaded directory // $clear_folder_before_upload = 1 or if you want to off this option then // $clear_folder_before_upload = 0 /////////////////////////////////////////////////////////////////////////// $clear_folder_before_upload = 1; function EmptyDir($dir) { $handle=opendir($dir); while (($file = readdir($handle))!==false) { @unlink($dir.'/'.$file); } closedir($handle); } ?> Any help would be greatly appreciated! Hello freaks! Im new to this forum, but im not all that new to PHP and MySQL. Although there's been some years since the last time I used it, so don't go all freaky on me if I dont do this right Let's go on-topic: Im in progress of making an internal web-page for me and my colleagues to make things a bit easier for us. I am making an database of our different projects, and I need some help with the input form - as I need to upload an image to the server, and store the path in the MySQL database. In my input form, I need to store information from text fields, and I need to upload an image to the server and store the path in the database. Before I can even start to code this (although I have coded the input forum without the upload), I need to know what would be the best way to do this. I guess there are several ways.. What would the expert do (That's you right?)? Should I have the information input, and image upload in the same form, or should I make a second form (maybe on a different page) for the upload? Is it necessary with two tables, one for the info and one for the image path, and then tie them together with the imageID, or is it fine to use just one table? Any thoughts would be appreciated! <!-- TechThat --> I have a PHP script that uploads images to a folder on my server (attachments folder). Currently the folder sits within my webroot and is publicly accessible (I have to use chmod 777 due to permissions issue). So, I created the "attachments" folder outside of my webroot (so that it is not publicly accessible), but I do not know how to set the path in the PHP code to upload it to that "attachments" folder outside of the webroot. As you see in the snippet of PHP code below, the code currently uploads the the "attachments" folder within the www (webroot) directory. How do I make it upload to the "attachments" folder OUTSIDE of the www (webroot) directory? foreach($files[$form] as $file){ $str = $file[1]; if (eval("if($str){return true;}")) { $_values[$file[0]] = $_FILES[$file[0]]["name"]; $dirs = explode("/","attachments//"); $cur_dir ="."; foreach($dirs as $dir){ $cur_dir = $cur_dir."/".$dir; if (!@opendir($cur_dir)) { mkdir($cur_dir, 0777);}} $_values[$file[0]."_real-name"] = "attachments/".date("YmdHis")."_".$_FILES[$file[0]]["name"]."_secure"; copy($_FILES[$file[0]]["tmp_name"],$_values[$file[0]."_real-name"]); @unlink($_FILES[$file[0]]["tmp_name"]); }else{ $flag=true; if ($_isdisplay) { //$ExtFltr = $file[2]; //$FileSize = $file[4]; if (!eval("if($file[2]){return true;}")){echo $file[3];} if (!eval("if($file[4]){return true;}")){echo $file[5];} $_ErrorList[] = $file[0]; } } } I need help making the uploaded image file name, that's chosen to be uploaded, be displayed on the html page with the path /upload/ added to the beginning of the displayed file name like so: ../upload/test.png Any help/improvements will be appreciated. <html> <head> <title>PHP Test</title> </head> <body> <?php if ($form_submitted == 'yes') { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if ( $_FILES["file"]["size"] < 200000 && in_array($extension, $allowedExts) ) { if ($_FILES["file"]["error"]!= 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { $length = 20; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename ); $file_location = '<a href="http://../upload/' . $newfilename . '">' . $newfilename . '</a>'; } } else { echo "Invalid upload file"; } ?> <label for="file">Filename:</label> <input type="file" name="file" id="file"> </body> </html> I am not sure whether this is an appropriate question for this forum but am hoping it might be. I have an image and intend to create a number of image maps of it so that readers can click on various parts of the image and then get a document coming up inviting them to write their thoughts about that part of the image. I am wondering whether it is possible, once they have written down their thoughts, for what they have written then to be superimposed on the image where the image map is? Thanks. Ok I have seen many posts on this script and many people asking question on this site. The script can be found..... http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ However I still can not make it work with what I have got. So here is the problem. First of all I upload the image and save the name to the database. I then pass its ID to the next page to retrieve the image and its path from the database. This is where the script comes in. I then run the image through the script and send you to the success page. Now the image is not being resized! The code is not erroring (even with error reporting on). It would seem the code it just get ignored completely. The image is still there and displays how it was uploaded but the size just hasnt changed. Im asuming Im using it in the correct way. Here is the code after the image has been uploaded. $Fetchq = mysql_query("SELECT * FROM images WHERE imageID ='".$_GET['image']."' ") or die('error stuff here'); $fetched = mysql_fetch_array($Fetchq); $path = "/members/images/members/merseyside/{$fetched['imagename']}"; include('SimpleImage.php'); $image = new SimpleImage(); $image->load('$path'); $image->resize(60,60); $image->save('$path'); $url = "/activity-photos.php?uploaded=true"; header("Location: $url"); Any help would be greatly appreciated as I've had enough of banging my head against this code wall OK, I think this is easy, but I just can't seam to get it figured out. I have this piece of code echo '<img src="maps/' . $map . '.jpg" />'; And what I want to do is if that $map is not in the directory I want it to display a standard image that I know is in the directory. So basically I want the alt tag to be a image instead of text. Hello Everybody
I usually work with C#, but I'm doing a website right now and have a question:
I want a picture in my header and when I change the window size the image may not move.
My code so far:
#a1 { position: relative; top:-175px; left:0px; width:50px; height:50px; background-image:url(http://domain.png); background-repeat:no-repeat;} </style>Hope someone can answer this question easy Hi guys, Happy New Year http://www.phpfreaks.com/forums/php-coding-help/?action=post How can i get the path http://www.phpfreaks.com/forums thanks, Hi guys, Here is what I have so far: http://www.autoshopgarage.com/new-era/generate.php What I am trying to do is instead of having Line 1 and Line 2, I want to just have one big textarea so I don't have to limit the user so much. I did it this way because I want to have two versions of text, the light version and the bold version. Is it possible to have two different fonts with just one textarea of text? Right now I have two functions: Quote ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); So I would limit that to just 1, and it would automatically wordwrap but what would I put for the $font variable? Is this even possible? I was thinking of just using BBCode so they could type in [b*]Bold Text[/b*] and it would use the Bold version of the font if it sees that. Any help is appreciated. Thanks! Here is the full code: Quote <?php $first = $_GET['first']; $last = $_GET['last']; $font_color = $_GET['color']; header("Content-type: image/png"); $image = imagecreatefrompng ( "banner_blank.png" ); $color_black = imagecolorallocate($image, 0, 0, 0); $color_red = imagecolorallocate($image, 255, 0, 0); if($font_color == "Red") { $color = $color_red; } elseif($font_color == "Black") { $color = $color_black; } $font1 = 'HelveticaNeueLTStd-BdEx.ttf'; $font2 = 'HelveticaNeueLTStd-LtEx.ttf'; $fontSize = "21"; ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); imagepng ( $image ); imagedestroy ( $image ); ?> Hi, I have a dynamic variable like this: /def/g/qaz/pol/cxz/cba/abc I only wish to keep this: /def/g/qaz/pol/cxz How would I do this? Thanks, - mme Can I use this path? I didn't know if I could pull in images into a subdomain from another domain ../mysite.com/assets/img/avatars/defaultuser.jpg my problem is when i click on hyperlink it start copying it self insertrow=yes in address bar how to tackle this Code: [Select] $httpquery = "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&insertrow=yes" ; <a href='{$httpquery}' >New</a> <br> if (isset($_GET['insertrow'])) { echo "<br> {$_GET['insertrow']} "; } Hi,
I am trying to setup cakephp cake console in win7 and run cake bake as in the link below.I set up the env variable in win7 as below with a php and cakeapp entry in this Path.I have easyPHP 12.1 and php works fine. I get an error with php in failing to load. dynamic library but the php dir is in the path below so I have no idea .
I cant set my php env var is my problem . The php.ini is in this dir specified below.
http://www.nurelm.co...ols-in-windows/
E:\Program Files\EasyPHP-12.1\php\php546x121019214357\;E:\AA-website design\acl\app\Console\;
|