$php_mysql$ Posted September 22, 2010 Share Posted September 22, 2010 anyone can show example how i could remane the uploaded file name with users id along with some number? //////////////////////////////////////uploader else if($action=="uploader") { echo "Upload your picture and copy the link <br/>after uploading to user it at gallery.<br/><br/>"; echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"index.php?action=uploaded&sid=$sid\">"; echo "Choose Picture: <br />"; echo "<input name=\"uploaded\" type=\"file\" /><br /><br />"; echo "<input type=\"submit\" value=\"Upload\" />"; echo "</form><br/>"; echo "<p align=\"center\">"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //////////////////////////////////////uploader else if($action=="uploaded") { $blacklist = array(".php", ".php.jpg", ".php.jpeg", ".php.gif", ".php.png", ".phtml", ".php3", ".php4"); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['uploaded']['name'])) { echo "<p align=\"center\">"; echo "Oops sorry we do not allow those files.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; exit; } } $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if (file_exists("../images/" . $_FILES["uploaded"]["name"])) { echo "<p align=\"center\">"; echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; }else{ //This is our size condition if ($uploaded_size > 25600){ echo "Your file is too large. We have a 25kb limit.<br/>"; $ok=0; } $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($_FILES['uploaded']['type'], $types)) { // file is okay continue } else { $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0){ echo "<p align=\"center\">"; Echo "Sorry your file was not uploaded.<br/> It may be the wrong filetype. <br/>We only allow JPG, GIF, and PNG filetypes.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //If everything is ok we try to upload it else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "<p align=\"center\">"; echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } else{ echo "<p align=\"center\">"; echo "Sorry, there was a problem uploading your file.<br/>"; echo "<br/><a href=\"http://index.php?action=main&sid=$sid\">Wml Home</a><br />"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } } } } [code] Quote Link to comment Share on other sites More sharing options...
Adam Posted September 22, 2010 Share Posted September 22, 2010 On this line of your code: if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ ..you specify the $target location to move the file; modify $target to contain the file name you want. Currently you have: $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; Replace it to something like: $target = "../images/"; $target = $target . md5(rand() . $_FILES['uploaded']['name']); Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 22, 2010 Author Share Posted September 22, 2010 one question i retrive my users name like this $nick = getnick_uid($username); how could i use this users name for the uploaded file? Quote Link to comment Share on other sites More sharing options...
Adam Posted September 22, 2010 Share Posted September 22, 2010 $target = "../images/"; $target = $target . getnick_uid($username); Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 22, 2010 Author Share Posted September 22, 2010 got it thanks :-) Quote Link to comment Share on other sites More sharing options...
Adam Posted September 22, 2010 Share Posted September 22, 2010 No problem. Although actually you'd may as-well remove the redefinition: $target = "../images/" . getnick_uid($username); Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 22, 2010 Author Share Posted September 22, 2010 ok how could i make this random number not random but goes serially? $randomnum=rand(0000,9999); currently it gives random numbers but i wish for it to you know like 1 2 3 4? Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 22, 2010 Author Share Posted September 22, 2010 another question :-) right now if i print $target i get image/filename.gif , how can i print only the finename.gif? Quote Link to comment Share on other sites More sharing options...
Adam Posted September 22, 2010 Share Posted September 22, 2010 basename Edit: Missed your other post. You'd need to use a data source such a database or flat file to store the current count. Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 22, 2010 Author Share Posted September 22, 2010 yes im storing them in DB but still not too clear on it. i have inboxed u the complete source, could u help find a solution? thanks Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 23, 2010 Author Share Posted September 23, 2010 any help here someone? Quote Link to comment Share on other sites More sharing options...
trq Posted September 23, 2010 Share Posted September 23, 2010 The issue is? Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 24, 2010 Author Share Posted September 24, 2010 ok the issue is, when i echo $target it prints the path and the renamed image name something like this images/username28374image.jpg but what im looking for is to get only username28374image.jpg without the images/ so that i could store the username28374image.jpg name into DB for after i store like images/username28374image.jpg im unable to delete the image from the dir. I want to get images/username28374image.jpg with $target but aswell i want a way to get only the image name like username28374image.jpg any help please? Quote Link to comment Share on other sites More sharing options...
Adam Posted September 24, 2010 Share Posted September 24, 2010 basename Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 24, 2010 Author Share Posted September 24, 2010 would it be something like this? $image_name = basename( $_FILES['uploaded']['name']) ; Quote Link to comment Share on other sites More sharing options...
Adam Posted September 24, 2010 Share Posted September 24, 2010 That would return the file name of the file they uploaded. So yeah, if that's what you're after. Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 24, 2010 Author Share Posted September 24, 2010 ok it does but not along with the renamed image but the original name of the image, currently to rename i did $target = "images/"; $randomnum=rand(0000,9999); $target = $target.getnick_username($username).$randomnum; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; the uploaded images gets stored like username2345_originalimagename.jpg but when im printing the $image_name = basename( $_FILES['uploaded']['name']) ; i get only originalimagename.jpg not along with username and the random number like username2345_originalimagename.jpg which gets uploaded Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 24, 2010 Author Share Posted September 24, 2010 finally i used my head :-) Quote Link to comment 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.