Guest Posted November 11, 2006 Share Posted November 11, 2006 Is there a way to upload a file in a form and send $_FILES['file']['name'] to a function for editing? Can someone please help. Thank You Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/ Share on other sites More sharing options...
joshi_v Posted November 11, 2006 Share Posted November 11, 2006 To upload the file use this one[code]<?php<form enctype="multipart/form-data" action="_URL_" method="POST"><input type="hidden" name="MAX_FILE_SIZE" value="30000">Send this file: <input name="userfile" type="file"><input type="submit" value="Send File"></form>?>[/code]Once you upload the file you can pass the file name to any function ($_FILES['file']['usefile']) Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123103 Share on other sites More sharing options...
Guest Posted November 11, 2006 Share Posted November 11, 2006 I tried to pass the file to the function and the function has no data if i upload an image name image1 and type filei send it to the function by $_FILES['image1'] and there is also no data inside the function lets say i wanted to get the size and the name in the function how would i send the file and how would i recive the file would i use $image or what on the function definition? Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123104 Share on other sites More sharing options...
joshi_v Posted November 11, 2006 Share Posted November 11, 2006 See!You can't checka filename like $_FILES['image1']you must use $_FILES['file']['name'].this will give the flename just upload!If you can post your code here it will be useful to help you! Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123112 Share on other sites More sharing options...
Guest Posted November 11, 2006 Share Posted November 11, 2006 I do this[code]function getFileExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext;}$ext = getFileExtension($_FILES['image1']['name']);[/code]$ext is blank i cant figue out why the functions are in different files included of course Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123214 Share on other sites More sharing options...
Orio Posted November 11, 2006 Share Posted November 11, 2006 Best way imo:[code]<?phpfunction getFileExtension($str){ if(strpos($str,".") === FALSE) return "": $parts = explode(".",$str); return $parts[count($parts) - 1];}?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123217 Share on other sites More sharing options...
Guest Posted November 11, 2006 Share Posted November 11, 2006 [code]getimagesize($_FILES['image1']['tmp_name'])Warning: getimagesize(/tmp/phpSULyxK) [function.getimagesize]: failed to open stream: No such file or directory in imagefunctions.php on line 81Warning: copy(/tmp/phpSULyxK) [function.copy]: failed to open stream: No such file or directory in[/code]I dont get whats going on if its not in functions all this works correctly. Is there somthing im missing am i doing it wrong? Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123250 Share on other sites More sharing options...
joshi_v Posted November 13, 2006 Share Posted November 13, 2006 Are you sure that image1 file is there on the location from where you are trying to get the size of it. Link to comment https://forums.phpfreaks.com/topic/26917-files-to-functions/#findComment-123875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.